public void insertAt(int loc, int data) { if (root == null && loc > 0) { Console.WriteLine("err: list empty"); } if (loc == 0) { insertStart(data); } Node current = root; try { for (int i = 0; i < loc - 1; i++) { Console.WriteLine("current Data {0}", current.getData()); current = current.getNode(); } Node newNode = new Node(current.getNode(), data); current.setNode(newNode); } catch (NullReferenceException e) { Console.WriteLine("err: location out of index"); Console.WriteLine(e); } }
public void insertEnd(int data) { if (root == null) { Node newNode = null; root = new Node(newNode, data); } else { Node current = this.root; while (current.getNode() != null) { current = current.getNode(); } Node newNode = new Node(null, data); current.setNode(newNode); } }