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 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++; } }