private SLNode Add(SLNode node, int data) { if (node == null) { return(new SLNode(data)); } node.Next = Add(node.Next, data); return(node); }
public int[] ToArray() { SLNode curr = root; List <int> l = new List <int>(); while (curr != null) { l.Add(curr.Data); curr = curr.Next; } return(l.ToArray()); }
static void RemoveDuplicates(SinglyLinkedList list) { SLNode root = list.GetRoot(); SLNode curr = root; int counter = 0; while (curr != null) { if (curr.Next == null) { break; } if ((counter & (1 << curr.Next.Data)) > 0) { curr.Next = curr.Next.Next; } counter |= 1 << curr.Data; curr = curr.Next; } }
public void Add(int data) { root = Add(root, data); }