Using system; using system. data; using system. configuration; using system. web; using system. web. security; using system. web. ui; using system. web. UI. webcontrols; using system. web. UI. webcontrols. webparts; using system. web. UI. htmlcontrols; // <summary> /// Summary of dlistnode /// </Summary> public class dlistnode {private int _ data; private dlistnode _ prenode; private dlistnode _ nextnode; Public int data {Get {return _ data;} set {_ DATA = value ;}} public dlistnode prenode {get {return _ prenode ;}set {_ prenode = value ;}} public dlistnode nextnode {get {return _ nextnode;} set {_ nextnode = value ;}} public class Dlist {private dlistnode _ firstnode; private int _ count; public int count {get {return _ count;} set {_ COUNT = value;} public dlistnode firstnode {get {return _ fir Stnode ;}set {_ firstnode = value ;}} /// <summary> /// Add the object to the end of the linked list /// </Summary> /// <Param name = "element"> </param> Public void add (INT element) {If (firstnode = NULL) // judge whether the first node is null {firstnode = new dlistnode (); // if it is null, the first node is added. data = element;} else {dlistnode dltmp = firstnode; // find the last node while (true) {If (dltmp. nextnode = NULL) // Insert a new node {dltmp. nextnode = new dlistnode (); Dltmp. nextnode. data = element; dltmp. nextnode. prenode = dltmp; break;} else {dltmp = dltmp. nextnode ;}} this. count ++; // Add 1} to the length of the linked list /// <summary> /// remove all elements /// </Summary> Public void clear () {This. firstnode = NULL ;} /// <summary> /// search for the index of the specified object /// </Summary> /// <Param name = "Temp"> </param> /// <returns> </returns> Public int indexof (INT temp) {dlistnode dltmp = This. firstnode; int Index = 0; While (true) {// if not found,-1 If (dltmp = NULL) {return-1;} else {If (dltmp. data = temp) // returns the index {Return Index;} dltmp = dltmp. nextnode; index ++ ;}}} /// <summary> /// Delete the specified operation from the linked list /// </Summary> /// <Param name = "Temp"> </param> Public void delete (INT temp) {dlistnode dltm = This. firstnode; while (true) {If (dltm = NULL) {return;} else {If (dltm. data = temp) {dlistnode dlpre = N EW dlistnode (); If (dltm. prenode! = NULL) {dlpre = dltm. prenode; dlpre. nextnode = dltm. nextnode; dltm. nextnode. prenode = dlpre; dltm = NULL;} else {This. firstnode = dltm. nextnode; dltm = NULL;} This. count --; break;} else {dltm = dltm. nextnode ;}}}} /// <summary> /// Add the specified operation to the linked list /// </Summary> /// <Param name = "Temp"> </param> Public void insert (INT temp) {dlistnode node = This. firstnode; while (true) {If (node = NULL) {return;} else {dlistnode newnode = new dlistnode (); newnode. data = temp; If (temp <node. data) {If (node. prenode = NULL) {node. prenode = newnode; newnode. nextnode = node; newnode. prenode = NULL; this. firstnode = newnode;} else {newnode. prenode = node. prenode; newnode. nextnode = node; node. prenode. nextnode = newnode; node. prenode = newnode;} This. count ++; break;} else {node = node. nextnode ;}}}}}
From: http://blog.csdn.net/bydxyj/article/details/4394734