Data structure - an array, single chain and double chain introduction and doubly linked linear list is a linear structure, it has the same type is n (n ≧ 0) finite sequence of data elements.

Linear table is a linear structure, it has the same type is n (n ≧ 0) finite sequence of data elements.

Array:

There are upper and lower bounds array, the array elements in the upper and lower bounds are continuous.

Array features are: the data is continuous; fast random access speed.
The array is slightly more complicated multidimensional array and dynamic arrays. For the C language, the nature of the multi-dimensional arrays is achieved by a one-dimensional array. As dynamic array is an array of volume index of dynamically growing group; for the C language, the arrays to provide dynamic, you need to manually implement; and for C ++ terms, STL provides the Vector.

Singly linked list:

Way linked list (single linked list) is a list, which consists of nodes, each node contains a pointer to the next node.

Header is empty, the subsequent node table header is "node 10" (data of 10 nodes), "node 10" successor node is the "node 20" (data of 10 nodes), "node 20" descendant node It is "node 30" (data node 20), "node 30" successor node is the "node 40" (data node 10), ......

Delete "node 30"
before deleting: "node 20" successor node "node 30" and "30 node" successor node "node 40."
After deleting: "node 20" successor node "node 40."

Between the "node 10" and the "node 20" Add "node 15"
before the addition: "Node 10" successor node "node 20."
After addition: "Node 10" successor node "node 15", and the "node 15" successor node "node 20."

Single chain is characterized by: the link is one-way direction of node; with respect to the array, a single list of random access is slower, but the singly linked list deletion / addition data is very efficient.

Doubly linked list:

Doubly linked list (doubly linked list) is a linked list. And a single list as a doubly linked list are nodes, each of which has two data pointers in the node, point to direct predecessor and successor directly. So, start from any one node in a doubly linked list, you can easily access its predecessor nodes and successor node. Generally, we have constructed two-way circular list.

Header is empty, the subsequent node header is "node 10" (data of 10 nodes); "node 10" successor node is the "node 20" (data of 10 nodes), "node 20" of the predecessor node is the "node 10"; "node 20" successor node is the "node 30", front "node 30" relay node is "node 20"; ...; successor node is the end node header.

Delete "node 30"
before deleting: "node 20" successor node "node 30", "30 node" of the predecessor node "node 20." Former "node 30" successor node "node 40", "40 node" relay node "node 30."
After deleting: "node 20" successor node "node 40", "40 node" of the predecessor node "node 20."

Added between "node 10" and "20 node" "node 15"
before adding: "node 10" successor node "node 20", "20 node" of the predecessor node "node 10."
After adding: "node 10" successor node "node 15", "15 node" of the predecessor node "node 10." "Node 15" successor node "node 20", "20 node" of the predecessor node "node 15."

C ++ STL's list doubly linked list container

→ to the front of the list chain, the head node of the first node → 2 → ... node n nodes of the first node configured → cycle.
list of the reverse strand, the n-th node by the n-1 → → nodes constituting the loop → ... → n-th node of the head node. n is the number of nodes of the list, the entire list of the storage location indicated by the head pointer, which points to the head node.

/ * 
1. List Initialization: 
(. 1) List <int> T; // no elements 
(2) list <int> t (10); // Create a list has 10 elements 
(3) list <int> t (10, 3); // Create a list has 10 elements, and each element is 3 
2. linked list insertion operation: 
(1) forward runs method: inserting a new element at the head of the list, the list automatically expand to form : 
t.push_front (. 8); 
(2) the end of interpolation: inserting a new element at the tail of the linked list, the list automatically expand to form: 
t.push_back (. 9); 
(. 3) interposed: with insert () function, the parameter is to iterator insertion position, for example: 
IT = t.begin (); 
It ++; // Note that only the list iterators ++ or - operation can not be performed n-+ 
t.Insert (IT, 20 is); / / operation 
traversing 3. list of: 
(1) reverse traversal: form: 
List <int> :: a reverse_iterator RIT; 
for (RIT t.rbegin = (); t.rend RIT = (); RIT ++!) 
(2) forward traversal: shape: 
List <int>: Iterator IT; 
for (IT = t.begin (); IT = t.end (); ++ IT!) 
4. removing elements
(1) remove () method removes an element, elements of the same value are deleted, the parameter value of the element, rather than iterator position, for example: t.remove (. 8); 
(2) using pop_front () method to delete the first element of the list, for example: t.pop_front (); 
(. 3) using pop_back () method removes the end of the list of elements, for example: t.pop_back (); 
(. 4) using the erase () method removes the element of the iterator's position, e.g. : 
IT = t.begin (); 
IT ++; // Note that only the list iterators ++ or - operation can not be performed n-+ 
IT ++; // operations, but for (it = t.begin (); ! it = t.end (); it ++) this does not affect 
t.erase (IT); 
(. 5) Clear (), empty list, for example: t.clear (); 
(. 6) size (), find one of the elements number, for example: << t.size COUT () << endl; 
(. 7) find (), find elements in the list, the header file #include <algorithm> If found, the position of the element is returned iterator, If not found, end is returned () position iterator. Find the form of: 
List <int> :: Iterator IT; 
IT = Find (t.begin (), t.end (),. 8); // This and other differences, list of sections have to find 
( 8) sort () method to sort the list, the default is ascending order, form: t.sort ();
* / 
(. 9) UNIQUE () method to remove continuously repeated elements, attention is continuously repeated elements,
Example 12 341 1 will not be allowed to delete. 

#include <the iostream> 
#include <algorithm> 
#include <List> 
the using namespace STD; 
int main () 
{ 
	List <int> L; 
	l.push_back (2); 
	l.push_back (. 5); 
	l.push_back (. 4) ; 
	l.push_back (. 4); 
	l.push_back (. 6); 
	l.push_back (. 4); 
	List <int> :: Iterator IT; 
	COUT << "removed before:" << endl; 
	for (IT = l.begin ();! = l.end (); IT ++) 
		cout << * IT << ""; 
	cout << endl; 
	l.unique (); // removed continuously repeated elements, leaving only a 
	cout << "removed after: "<< endl; 
	for (IT = l.begin (); = l.end (); ++ IT!) 
		cout << * IT <<" "
}

  

Guess you like

Origin www.cnblogs.com/277223178dudu/p/11424067.html