示例#1
0
 public void AddToEnd(int data)
 {
     if (headNode == null)
     {
         headNode = new SingleLinkNode(data);
     }
     else
     {
         headNode.addToEnd(data);
     }
 }
示例#2
0
 public void addToEnd(int data)
 {
     if (next == null)
     {
         next = new SingleLinkNode(data);
     }
     else
     {
         next.addToEnd(data);
     }
 }
示例#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;
     }
 }
示例#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);
        }
示例#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);
     }
 }
示例#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);
     }
 }
示例#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);
        }
示例#8
0
 public SingleLinkNode(int data)
 {
     this.data = data;
     next      = null;
 }
示例#9
0
 public LinkedList()
 {
     headNode = null;
 }