Example #1
0
        public void HeadRemove()
        {
            if(IsEmpty) return;

            nodes--;
            Head = Head.Next;
        }
Example #2
0
 /// <summary>
 /// Finds the end of the list and adds a node
 /// </summary>
 /// <param name="data"></param>
 public void AddToEnd(int data)
 {
     if (_headNode == null)
         _headNode = new Node(data);
     else
         _headNode.AddToEnd(data);
 }
Example #3
0
 public void AddSorted(int data)
 {
     if (_headNode == null)
         _headNode = new Node(data);
     else if (_headNode.data > data)
         AddToBeginning(data);
     else
         _headNode.AddSorted(data);
 }
Example #4
0
 /// <summary>
 /// Adds new node as the head points the new head node to the previous head node.
 /// </summary>
 /// <param name="data"></param>
 public void AddToBeginning(int data)
 {
     if (_headNode == null)
         _headNode = new Node(data);
     else
     {
         Node tempNode = new Node(data);
         tempNode.next = _headNode;
         _headNode = tempNode;
     }
 }
        public void AddNewNode(string n)
        {
            Node newNode = new Node();

            newNode.Name = n;
            Node cur = head;
            while (cur.next != null)
            {
                cur = cur.next;
            }
            cur.next = newNode;
            listCount++;
        }
 public SingleLinkedList(string n)
 {
     head = new Node();
     head.Name = n;
     listCount++;
 }
 public SingleLinkedList()
 {
     head = new Node();
     listCount++;
 }
Example #8
0
 public Node(uint _value = 0, Node _next = null)
 {
     Value = _value;
     Next = _next;
 }
Example #9
0
 public void HeadInsert(uint x)
 {
     nodes++;
     Head = new Node(x, Head);
 }
Example #10
0
 /// <summary>
 /// A new list with no pointers
 /// </summary>
 public List()
 {
     _headNode = null;
 }
Example #11
0
 /// <summary>
 /// Checks if the data held in the next node is equal to the data to be removed. 
 /// If true moves the pointer of the current node to the node that the next node points to.
 /// This leaves the next node with no pointer to be cleaned up by garbage collection. 
 /// Calling Garbage collection manually is not recomended as it can make the program unstable. 
 /// </summary>
 /// <param name="data"></param>
 public void Delete(int data)
 {
     if (this.next.data == data)
         this.next = next.next;
     else
         next.Delete(data);
 }
Example #12
0
 /// <summary>
 /// Checks if the current "next" node is null if not calls the method again with the next linked node.
 /// </summary>
 /// <param name="data"></param>
 public void AddToEnd(int data)
 {
     if (next == null)
         next = new Node(data);
     else
         next.AddToEnd(data);
 }
Example #13
0
 /// <summary>
 /// Checks if current data is less than the next.data if yes than add before and adjust the links.
 /// </summary>
 /// <param name="data"></param>
 public void AddSorted(int data)
 {
     if (next == null)
         next = new Node(data);
     else if (data < next.data)
     {
         Node temp = new Node(data);
         temp.next = this.next;
         this.next = temp;
     }
     else
         next.AddSorted(data);
 }
Example #14
0
 /// <summary>
 /// This constructor takes a int. As the class in created it sets the data and points to null. 
 /// </summary>
 /// <param name="i"></param>
 public Node(int i)
 {
     data = i;
     next = null;
 }