Compared with Arrays:
Advantage: quick access to array elements through indexes (array subscript;
Disadvantage: the array needs to be adjusted to insert/delete elements, which is inefficient;
Linked List:
Advantage: Fast insertion/deletion speed and adjustment of the entire linked list;
Disadvantage: Only sequential access is allowed and random access is allowed (subscript is used for Array samples );
The linked list needs to be quickly inserted/deleted, and used when it is too concerned or requires random access.
Using system; namespace singly_linked_list {class program {static void main (string [] ARGs) {singly1_list lst = new singly1_list (); lst. add (1); lst. add (2); lst. add (3); lst. add (4); lst. add (5); lst. add (6); lst. deletenext (); lst. deletenext (); lst. deletenext (); console. writeline (lst. tostring (); console. read () ;}} class singly+list {// number of elements Private int count; // The end pointer private node next; private node temp; // Add the public void add (object Value) Element) {node newnode = new node (value); If (this. next = NULL) // The linked list is empty. This. next = newnode; else {// The linked list is not empty. Add the element to the end of the linked list if (temp = NULL) {This. next. next = newnode; temp = newnode;} else {temp. next = newnode; temp = newnode;} // You can also use the following method // If (this. next = NULL) // The linked list is empty // This. next = newnode; // else // {// If (this. next. next = NULL) // This. next. next = newnode; // else {// node n1 = This. next. next; // For (INT I = 1; I <count; I ++) // {// If (n1.next = NULL) // n1.next = newnode; // else // n1 = n1.next; //} count ++;} public override string tostring () {If (this. next = NULL) {return string. empty;} string S = ""; node temp = This. next; For (INT I = 0; I <count; I ++) {S + = temp. tostring () + ""; temp = temp. next;} return s;} // chain table length public int count {get {return count ;}}// Delete public int deletenext () {If (this. next = NULL) return 0; If (this. next. next = NULL) This. next = NULL; else this. next = This. next. next; count --; return 1;} private class node {public node (object Value) {item = value;} // stores public object item; Public singly1_list. node next; Public override string tostring () {return item. tostring ();}}}}
Running result: