Beispiel #1
0
 private SLNode Add(SLNode node, int data)
 {
     if (node == null)
     {
         return(new SLNode(data));
     }
     node.Next = Add(node.Next, data);
     return(node);
 }
Beispiel #2
0
        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());
        }
Beispiel #3
0
        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;
            }
        }
Beispiel #4
0
 public void Add(int data)
 {
     root = Add(root, data);
 }