public void Push(string strIn)
		{
			Node oldFirst = first;
			this.first = new Node ();
			first.Item = strIn;
			first.Next = oldFirst;
		}
        public void delete(string toDelete)
        {
            Node currNode = top;
            bool found = false;

            if (currNode != null)
            {
                //If there are items in the list, look for node to delete
                if (currNode.Equals(toDelete))
                {
                    //If the top node is the node to delete, set top to top.next
                    top = currNode.getNext();
                    size--;
                }
                else
                {
                    //If the top node is not the node to delete, check through the linked list and delete the node if found
                    while (currNode != null && currNode.getNext() != null && found == false)
                    {
                        if (currNode.getNext().Equals(toDelete))
                        {
                            currNode.setNext(currNode.getNext().getNext());
                            size--;
                            found = true;
                        }
                        currNode = currNode.getNext();
                    }
                }
            }
            //If there are no items in the list, do nothing
        }
 public void deleteFromFront()
 {
     if(top != null)
     {
         top = top.getNext();
         size--;
     }
 }
		public string Pop()
		{
			if (this.IsEmpty()) {
				return "Empty";
			}
			string item = this.first.Item;
			first = first.Next;
			return item;
		}
        public object Pop()
        {
            if (_root != null)
            {
                object data = _root.Data();
                _root = _root.Next;
                _count--;
                return data;
            }

            throw new Exception("Trying to pop from empty Stack");
        }
        public void Push(object toAdd)
        {
            Node newNode = new Node(toAdd);

            if (_count++ == 0)
            {
                _root = newNode;
                return;
            }

            newNode.Next = _root;
            _root = newNode;
        }
 public Stack()
 {
     _count = 0;
     _root = null;
 }
        private static void nodeTest()
        {
            Node node1 = new Node("test");
            Node node1_2 = new Node("test");
            Node node2 = new Node("another test node");

            Console.Out.WriteLine("======>Node Test 1<======");
            Console.Out.WriteLine(">>Test whether or not a node returns the correct data");
            Console.Out.WriteLine("returned: " + node2.getData());
            Console.Out.Write("Test Passed: ");
            Console.Out.WriteLine(String.Equals(node2.getData(), "another test node"));

            Console.Out.WriteLine("");
            Console.Out.WriteLine("======>Node Test 2<======");
            Console.Out.WriteLine(">>Test whether or not the node equals method works");
            Console.Out.Write("Test Passed: ");
            Console.Out.WriteLine(node1.Equals(node1_2.getData()));

            Console.Out.WriteLine("");
            Console.Out.WriteLine("======>Node Test 3<======");
            Console.Out.WriteLine(">>Test whether or not the node setNext and getNext methods work");
            node1.setNext(node2);
            node2.setNext(node1_2);
            Console.Out.Write("Test Passed: ");
            Console.Out.WriteLine(String.Equals(node1.getData(), node1.getNext().getNext().getData()));
            Console.Out.WriteLine("");
        }
 public LinkedList()
 {
     top = null;
     size = 0;
 }
 public void setNext(Node newNext)
 {
     next = newNext;
 }
 public Node(string newData)
 {
     data = newData;
     next = null;
 }
        public void insertAtFront(String data)
        {
            Node newNode = new Node(data);

            if (top == null)
            {
                //The LinkedList is empty so set top to the new node
                top = newNode;
                size++;
            }else{
                //The LinkedList contains elements, so set the newNode.next to the top and set top to the newNode
                newNode.setNext(top);
                top = newNode;
                size++;
            }
        }
Example #13
0
 public Node(object data)
 {
     _data = data;
     Next = null;
 }