Exemplo n.º 1
0
        public void insertAt(int loc, int data)
        {
            if (root == null && loc > 0)
            {
                Console.WriteLine("err: list empty");
            }
            if (loc == 0)
            {
                insertStart(data);
            }
            Node current = root;

            try
            {
                for (int i = 0; i < loc - 1; i++)
                {
                    Console.WriteLine("current Data {0}", current.getData());
                    current = current.getNode();
                }
                Node newNode = new Node(current.getNode(), data);
                current.setNode(newNode);
            }
            catch (NullReferenceException e)
            {
                Console.WriteLine("err: location out of index");
                Console.WriteLine(e);
            }
        }
Exemplo n.º 2
0
        public void writeList()
        {
            if (this.root == null)
            {
                Console.WriteLine("List is empty");
            }

            Node current = this.root;

            Console.WriteLine(current.getData());
            while (current.getNode() != null)
            {
                current = current.getNode();
                Console.WriteLine(current.getData());
            }
        }
Exemplo n.º 3
0
 public void insertEnd(int data)
 {
     if (root == null)
     {
         Node newNode = null;
         root = new Node(newNode, data);
     }
     else
     {
         Node current = this.root;
         while (current.getNode() != null)
         {
             current = current.getNode();
         }
         Node newNode = new Node(null, data);
         current.setNode(newNode);
     }
 }