Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ Learning C ++ Standard Template Library and data structures     - configuration ssh without password under Linux (Linux)

- The strings in Python reside (Programming)

- Experts teach you how to identify the actual functional differences between the firewall (Linux)

- MySQL completely uninstall and install Configuring Character Sets under Linux (Database)

- How to make Linux a non-root user uses less than 1024 ports (Linux)

- Java implementation file encryption and decryption (Programming)

- VNC configuration detailed analysis under Linux (Linux)

- Experience RHEL7 new features (Linux)

- Linux common network tools: Scan routing of mtr (Linux)

- Ubuntu How to install screen recording tool Simple Screen Recorder 0.3.1 (Linux)

- MySQL Tutorial: Philosophical Reflections on the unauthenticated user (Database)

- HTTPS Encryption Algorithm (Linux)

- ActiveMQ memory settings and flow control (Linux)

- HTTP and FTP TCP-FLOOD CC Attacks Analysis and Prevention solutions under CentOS 6.5 (Linux)

- Configure the Linux kernel and use iptables to do port mapping (Linux)

- Java Access Control (Programming)

- Debian Stable (Jessie 8.1) of normal.mod not found (Linux)

- numpy and SciPy installation under Python for scientific computing package (Linux)

- GitLab Guide installation under Ubuntu 14.04 (Server)

- Linux system performance and usage activity monitoring tools -Sysstat (Linux)

  Learning C ++ Standard Template Library and data structures
  Add Date : 2018-11-21      
  STL (Standard Template Library), namely, the standard template library, an industrial-strength, efficient C ++ library. It is housed in the C ++ standard library (C ++ Standard Library), and is the ANSI / ISO C ++ standard part of the great revolutionary. The library contains a lot of basic data structures and basic algorithms in computer science in the common. For the majority of C ++ programmers it provides an extensible application framework, reflecting the high degree of software reusability.

Experience the STL list

STL class list provided, is a two-way circular linked list class. From every element (node), you can access a front element and a rear element. In STL, list provides a series of member functions, but in reality is the complete list of the basic operations, and other data structures are not as basic operations, but in engineering commonly used functions.


int data [6] = {3,5,7,9,2,4};
list < int> lidata (data, data + 6); // list is a template class with < int> showed that the data elements of type int
lidata.push_back (6);

When the list is initialized, space applications is 6, stored under the data of the six elements, when the lidata insert the first seven elements of "6", list apply for a new node element, is inserted into the list list, the data storage structure

list used in the program
The following program demonstrates the use of a more complete list of the process. We can see, just use #include in the header (this header provide a statement of class list), list class preset function that is capable of easy to use, and the type of data elements, relying on template mechanism can be used freely.

#include < iostream>
#include < list>
#include < numeric>
#include < algorithm>

using namespace std;

// Create a list of examples of container LISTINT
typedef list < int> LISTINT;

// Create a list of examples of container LISTCHAR
typedef list < char> LISTCHAR;

int main ()
    // --------------------------
    // Handle integer data list containers
    // --------------------------
    // Create a list object named listOne with LISTINT
    LISTINT listOne;
    // Declare i as the iterator
    LISTINT :: iterator i;

    // Add the front face listOne container data
    listOne.push_front (2);
    listOne.push_front (1);

    // Add data from the vessel for listOne
    listOne.push_back (3);
    listOne.push_back (4);

    // In front of the display data listOne backwards
    cout << "listOne.begin () --- listOne.end ():" << endl;
    for (i = listOne.begin (); i = listOne.end ();! ++ i)
        cout << * i << "";
    cout << endl;

    // Display the data from the back listOne
    LISTINT :: reverse_iterator ir;
    cout << "listOne.rbegin () --- listOne.rend ():" << endl;
    for (ir = listOne.rbegin (); ir = listOne.rend ();! ir ++)
        cout << * ir << "";
    cout << endl;

    // Use the STL accumulate (cumulative) algorithm
    int result = accumulate (listOne.begin (), listOne.end (), 0);
    cout << "Sum =" << result << endl;
    cout << "------------------" << endl;

    // --------------------------
    // Handle character data list containers
    // --------------------------

    // Create a list object named listOne with LISTCHAR
    LISTCHAR listTwo;
    // Declare i as the iterator
    LISTCHAR :: iterator j;

    // Add the front face listTwo container data
    listTwo.push_front ( 'A');
    listTwo.push_front ( 'B');

    // From the container to add data for listTwo
    listTwo.push_back ( 'x');
    listTwo.push_back ( 'y');

    // In front of the display data listTwo backwards
    cout << "listTwo.begin () --- listTwo.end ():" << endl;
    for (j = listTwo.begin (); j = listTwo.end ();! ++ j)
        cout << char (* j) << "";
    cout << endl;

    // Use the STL max_element algorithm for listTwo largest element and display
    j = max_element (listTwo.begin (), listTwo.end ());
    cout << "The maximum element in listTwo is:" << char (* j) << endl;
    return 0;

list class member functions
The list provides a rich member functions to achieve a variety of operations on the list. This gives the user the convenience, hidden behind, rigorous software engineering processes manufactured products, to ensure the quality. Therefore, in the development of the actual project, the following member function, or the establishment of feeling it.

assign () assign to the list
back () returns the last element
clear () Removes all elements
empty () if the list is empty, it returns true
end () returns the end iterator
erase () removes an element
front () returns the first element
get_allocator () returns the list of Configurator
insert () to insert an element in the list
max_size () returns the maximum number of elements in the list can hold
merge () merge two list
pop_back () to delete the last element
pop_front () removes the first element
push_back () at the end of the list to add an element
push_front () in the list of add an element to the head
rbegin () returns a pointer to the first element of a reverse iterator
remove () removes elements from the list
remove_if () to remove elements specified conditions
rend () points to end list reverse iterator
resize () changes the size of the list of
reverse () reverse elements of the list
size () Returns the number of elements in the list
sort () to sort the list
splice () merge two list
swap () swaps two list
unique () to delete duplicate elements in list

With STL, learn what data structure to do?

Oh, STL so well defined data storage structure became categories, including basic operations and frequently used functions are implemented by member functions, know the interface, you're done, every minute thing.
Yes, the problem came. There are so convenient "infrastructure", a lot of effort to learn what data structures class?
First, as a professional, you may be doing the "bottom", and the development of better stuff than the STL, you can have this ideal, this demand has been;
Second, the socket will read the manual writing code is the code slave, knows its internal round after round, to be able to navigate through the current library, you can use a good infrastructure, produce a truly high-quality products. Said here know that not every line of code to the nuanced and clear, but its internal principle of "feeling", which is the professional should have. Expert to use something, you have to become experts.
Third, again full of tools, there is always imperfect, when faced with a demand, there is no infrastructure, only the own making. No data structure skills, find someone else made it. Easy to find someone else, but the problem is the key when you withdraw, the withdrawal go?
Fourth, the data structure is professional knowledge, not just to work, or to guide thinking. Even if only that ability, the most important in the end is the hand or brain is more important, is not self-evident.

On the way we know these know why they are, progressive bar. Based data structure, practical STL, can have.

Just just now, in answering a student district, he said "content too much too complicated." I replied: "Is there any way to life is to struggle?." When crossed the mountain, turn back, but only a small hill, because you're already in high places.
- Linux System Tutorial: Ubuntu on the desktop is disabled by default keyring to unlock tips (Linux)
- Linux Tutorial Share: How to sudo command to define the PATH environment variable (Linux)
- Android Studio Installation and Configuration Guide tutorial (Linux)
- C # socket udp broadcast (Programming)
- Linux Network Programming - raw socket instance: MAC Address Scanner (Programming)
- CentOS / Linux SWAP partitions added (Linux)
- Windows7 / 8 / 8.1 hard drive to install Ubuntu 14.04 dual system (Linux)
- Java memory model subclasses (Programming)
- To install Gitolite in Ubuntu / Fedora / CentOS (Linux)
- Android working with Volley Comments (Programming)
- Ubuntu install Lighttpd + Mono support .net (Linux)
- Ubuntu 14.04 Docker installation (Linux)
- DataGuard the MRP can not start to analyze and solve problems (Database)
- Installation Eduspec university management systems 17 Linux Mint (Server)
- Setting Hibernate connection MySQL database connection pool coding (Database)
- Let's Encrypt with semiautomatic into Nginx configuration https (Server)
- How to deploy Python Web application: Heroku deployment process complete records (Server)
- RedHat command line and graphical interface switching (Linux)
- Differences Shell scripting languages and compiled languages (Programming)
- Spacewalk remove packages install the update (Linux)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.