First define the type type, define, the previous normal domain, the latter pointer domain, as follows
Using System; Namespace List {Name PUBLIC CLASTNODE {public ListNode (int newvalue) {value = newvalue;} Previous public listnode next; value publici;}}
Using system; namespace list {Link table class
After defining the node, the operation of the class linear table is programmed. In the List class, HEAD, TAIL, CURRENT, three pointers, using append, movefrist, moletprevious, mapcent, movest, delete, insertascending, insertunascending, clean Implement moving, adding, deleting, ascending, descending, descending, empty linked table operation, getCurrentValue () method obtains the current value.
Public class clist {public clist ()
{// Constructor // Initialization ListCountValue = 0; Head = NULL; TAIL = NULL;}
Head pointer private listnode head; tail pointer Private ListNode Tail;
Current pointer private listnode current;
Number of linked table data private int ListCountValue;
Tissue Add Data Public Void Append (int DataValue) {listnode new = new listNode (data); if (isnull ())
// If the head pointer is empty
{Head = newNode; tail = newnode;} else {tail.next = newNode; newode.previous = tail; tail = newnode;}
Current = newNode;
// Link table data number plus one listCountValue = 1;} Delete the current data public void delete () {// If the empty list If (! Isnull ()) {// If you delete the head IF (ISBOF ()) {head = Current.next; current = head; listCountValue- = 1; return;}
// If you delete the tail IF (ISEOF ()) {tail = current.previous; current = tail; listCountValue- = 1; return;}
// If you delete the intermediate data current.previous.next = current.next; current = current.previous; listcountvalue- = 1; Return;}
}
/// moving a data (! ISeof ()) current = current.next;} /// moving a data () {if (! Isbof ()) CURRENT = Current.previous;} /// move to the first data public void frist () {current = head;} /// move to the last data () {current = tail;}
/// Judgment whether it is empty list public bool isnull () {if (listcountvalue == 0) Return True;
Return false;}
/// Judgment whether it is reaching the tail public bool ISEOF () {if (current == tail) Return True; Return False;}
/// Judgment whether it is to reach the head member public bool ISBOF () {if (current == HEAD) Return True; Return False;
}
Public int getCurrentValue () {return current.value;} // Number of data for gaining Links PUBLIC INT LISTCOUNT {Get {Return ListCountValue;}}
/// Empty Link Picture Public Void Clear () {MoveFrist (); while (! Isnull ()) {// If it is not empty, delete () from the tail ();}}
/// Insert data PUBLIC VOID INSERT (INT DataValue) {listNode (ISNULL ()) {// is a blades, then add append (datavalue); return;}
IF (isbof ()) {// is inserted into newnode.next = head; head.previous = newNode; head = newNode; current = head listcountValue = 1; return;} // Insert NewNode.Next = CURRENT; newNode .Previous = current.previous; current.previous.next = newNode; current.previous = newNode; current = new; listCountValue = 1;}
/// In-order insertion into public void insertascending (int INSERTVALUE) {// Parameter: InsertValue Inserted data // is an empty list if (isnull ()) {// Add append (insertValue); return;}
// Move to Head MoveFrist (); if ((InsertValue // Move to Head MoveFrist (); if (InsertValue> getCurrentValue ()) {// meets the condition, insert, exit insert (InsertValue); return;} while (TRUE) {if (InsertValue> getCurrentValue ()) {// The full manual conditions are inserted, exiting insert (InsertValue); Break;} if (ISEOF ()) {// Tail Add append (InsertValue); Break;} // Move to the next pointer MoveNext ();}}}} Ok, a simple chain class is implemented, of course, there are many features, you can add it according to your needs. To Be Continue.