C # generic collection of - list

The basis of the list

1. Overview: -LinkedList list in C # generic collection is a doubly linked list, which is a node LinkedListNode structure wherein the node structure comprising: Next, Previous, Value of three parts. And a node value may be repeated.

Insertion puncturing list faster than Link Link substantially sequential type, can be used foreach. The list does not work!

2. The list is created and initialized:

(1) LinkedList <type> name list = new LinkedList <type> ();

(2) LinkedList <type> name list = new LinkedList <type> (array name);

Note : LinkedList <type> name list = new LinkedList <type> () {value}; this is wrong because the LinkedList node element should not be a simple LinkedListNode value!

  1. Linked list of nodes created and initialized:

LinkedListNode <type> node name = new LinkedListNode <type> (value);

// node must be built in the beginning of the assignment, the type to point before and after the read-only, can not be modified.

4. The basic operation of the list:

(1) take the first element of the list: the list name list name .First .Last // returns the node type

Before and after (2) moves linked list of nodes: node .Next .Previous // returns the node type nodes

Length (3) list of statistics: the chain name .Count (); // () parenthesis there all right

   List name. (LongCount ()) // must have parentheses

(4) adding the node:

List name .AddFirst (); // in parentheses is the node value or adding the list head

List name .AddLast (); // parameters as above, add the end of the list

Chain name .AddBefore (a parameter: adding position as node type, two parameters: the additive elements, or a node type value);

Chain name .AddAfter (a parameter: adding position as node type, two parameters: the additive elements, or a node type value);

(5) Delete node:

List name .Remove (); // value in parentheses is the linked list, if the value is present in the plurality of nodes, only one is removed first. Parenthesis value may also be a node type, but be aware that this node must be obtained from the original list, otherwise it will run error

List name .RemoveFirst (); // delete the first node, the first node will automatically move back

List name .RemoveLast (); // delete the end node, the end node will automatically forward

(6) Find the node values: Returns a Boolean

 List name .Contain (); in brackets the value of the node, the node is not

(7) Find the node: node type return value  

.Find list name (); in brackets the value of the node, the node is not. If the same values ​​of the plurality of nodes, and returns only the first

List name .FindLast (); and Find just the same as looking forward from the back

(8) in the list, to the two nodes is determined whether or not a node with the same number ==, .Equals to use the node (node);

(9) Clear the list: the list name .Clear ();

Guess you like

Origin www.cnblogs.com/fangexuxiehuihuang/p/11621450.html