Ejemplo n.º 1
0
 public void AddToEnd(int data)
 {
     if (headNode == null)
     {
         headNode = new SingleLinkNode(data);
     }
     else
     {
         headNode.addToEnd(data);
     }
 }
Ejemplo n.º 2
0
 public void addToEnd(int data)
 {
     if (next == null)
     {
         next = new SingleLinkNode(data);
     }
     else
     {
         next.addToEnd(data);
     }
 }
Ejemplo n.º 3
0
 public void AddToBegining(int data)
 {
     if (headNode == null)
     {
         headNode = new SingleLinkNode(data);
     }
     else
     {
         SingleLinkNode temp = new SingleLinkNode(data);
         temp.next = headNode;
         headNode  = temp;
     }
 }
Ejemplo n.º 4
0
        public int getMax()
        {
            int            max     = this.data;
            SingleLinkNode current = next;

            while (current != null)
            {
                if (current.data > max)
                {
                    max = current.data;
                }
                current = current.next;
            }
            return(max);
        }
Ejemplo n.º 5
0
 public void AddSorted(int data)
 {
     if (headNode == null)
     {
         headNode = new SingleLinkNode(data);
     }
     else if (data < headNode.data)
     {
         AddToBegining(data);
     }
     else
     {
         headNode.AddSorted(data);
     }
 }
Ejemplo n.º 6
0
 public void AddSorted(int data)
 {
     if (next == null)
     {
         next = new SingleLinkNode(data);
     }
     else if (data < next.data)
     {
         SingleLinkNode temp = new SingleLinkNode(data);
         temp.next = this.next;
         this.next = temp;
     }
     else
     {
         next.AddSorted(data);
     }
 }
Ejemplo n.º 7
0
        public void reverse()
        {
            if (headNode == null)
            {
                return;
            }
            SingleLinkNode prev    = null;
            SingleLinkNode current = headNode;
            SingleLinkNode next    = current.next;

            while (next != null)
            {
                current.next = prev;
                prev         = current;
                current      = next;
                next         = current.next;
            }
            headNode = prev;
            AddToBegining(current.data);
        }
Ejemplo n.º 8
0
 public SingleLinkNode(int data)
 {
     this.data = data;
     next      = null;
 }
Ejemplo n.º 9
0
 public LinkedList()
 {
     headNode = null;
 }