Beispiel #1
0
 public void Traverse(GroceryList node)
 {
     if (node == null)
     {
         node = this;
     }
     while (node != null)
     {
         Console.WriteLine(node.item);
         node = node.next;
     }
 }
Beispiel #2
0
 public int DeleteNext()
 {
     if (next == null)
     {
         return(0);
     }
     else
     {
         GroceryList node = this.next;
         this.next = this.next.next;
         node      = null;
         return(1);
     }
 }
Beispiel #3
0
        public GroceryList InsertNext(string value)
        {
            GroceryList node = new GroceryList(value);

            if (this.next == null)
            {
                this.next = node;
                node.next = null;
            }
            else
            {
                GroceryList temp = this.next;
                node.next = temp;
                this.next = node;
            }
            return(node);
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            SingleList n1 = new SingleList(1);
            SingleList n2 = n1.InsertNext(2);
            SingleList n3 = n2.InsertNext(3);
            SingleList n4 = n3.InsertNext(4);

            Console.WriteLine("Traverse");
            n1.Traverse(n1);
            Console.WriteLine("Deleting node 2");
            n1.DeleteNext();
            Console.WriteLine("Traverse");
            n1.Traverse(null);

            GroceryList i1 = new GroceryList("item1");
            GroceryList i2 = i1.InsertNext("item2");
            GroceryList i3 = i2.InsertNext("item3");
            GroceryList i4 = i3.InsertNext("item4");

            Console.WriteLine("Traverse");
            i1.Traverse(i1);
            Console.WriteLine("Deleting node 2");
            i1.DeleteNext();
            Console.WriteLine("Traverse");
            i1.Traverse(null);

            DList dl = new DList();

            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine("Enter Number " + (i + 1) + " ");
                dl.insert(Convert.ToInt32(Console.ReadLine()));
            }
            Console.WriteLine();
            dl.print();
            dl.Delete(Convert.ToInt32(Console.ReadLine()));
            dl.print();
        }
Beispiel #5
0
 public GroceryList(string i)
 {
     item = i;
     next = null;
 }
Beispiel #6
0
 public GroceryList()
 {
     item = null;
     next = null;
 }