public void AddAt(int index, NodeString dataToAdd) { int count = 0; Node currNode = top; Node toAdd = new Node(dataToAdd); while (currNode != null && count < index) { count++; currNode = currNode.GetNext(); } if (currNode != null && count == index - 1) { if (currNode.GetNext() != null) { toAdd.SetNext(currNode.GetNext()); currNode.SetNext(toAdd); } else { currNode.SetNext(toAdd); last = toAdd; } size++; } }
public void AddToBack(NodeString dataToAdd) { Node toAdd = new Node(dataToAdd); if (top == null) { top = toAdd; last = toAdd; } else { last.SetNext(toAdd); } size++; }
public void Delete() { if (top != null) { if (top.GetNext() != null) { top = top.GetNext(); } else { top = null; last = null; } size--; } }
public void SetNext(Node newNext) { nextNode = newNext; }
public Node(NodeString data) { this.data = data; nextNode = null; }
public LinkedList() { top = null; last = null; size = 0; }
public void DeleteFromEnd() { Node prevNode = null; Node currNode = top; if (currNode != null) { if (currNode.GetNext() != null) { while (currNode.GetNext() != null) { prevNode = currNode; currNode = currNode.GetNext(); } prevNode.SetNext(null); last = prevNode; } else { top = null; last = null; } size--; } }
public void DeleteAt(int position) { int count = 0; Node currNode = top; while (count < position && currNode != null) { count++; currNode = currNode.GetNext(); } if (currNode != null && count == position - 1) { if (currNode.GetNext() != null) { if (currNode.GetNext().GetNext() != null) { currNode.SetNext(currNode.GetNext().GetNext()); } else { currNode.SetNext(null); last = currNode; } size--; } } }
public void SetUp() { newNode = new Node(56); }