public int DeleteNext() { if (this.next == this) { System.Console.WriteLine("\nThe node can not be deleted as there is only one node in the circular list"); return(0); } SLinkCircularList node = this.next; this.next = this.next.next; node = null; return(1); }
public void Traverse(SLinkCircularList node) { if (node == null) { node = this; } System.Console.WriteLine("\n\nTraversing in Forward Direction\n\n"); SLinkCircularList startnode = node; do { System.Console.WriteLine(node.data); node = node.next; }while (node != startnode); }
public int GetNumberOfNodes(SLinkCircularList node) { if (node == null) { node = this; } int count = 0; SLinkCircularList startnode = node; do { count++; node = node.next; }while (node != startnode); System.Console.WriteLine("\nCurrent Node Value: " + node.data.ToString()); System.Console.WriteLine("\nTotal nodes in Circular List: " + count.ToString()); return(count); }
public SLinkCircularList InsertNext(int value) { SLinkCircularList node = new SLinkCircularList(value); if (this.next == this) // only one node in the circular list { // Easy to handle, after the two lines of executions, // there will be two nodes in the circular list node.next = this; this.next = node; } else { // Insert in the middle SLinkCircularList temp = this.next; node.next = temp; this.next = node; } return(node); }
public SLinkCircularList(int value) { data = value; next = this; }
public SLinkCircularList() { data = 0; next = this; }