public void AddToEnd(int data) { if (headNode == null) { headNode = new SingleLinkNode(data); } else { headNode.addToEnd(data); } }
public void addToEnd(int data) { if (next == null) { next = new SingleLinkNode(data); } else { next.addToEnd(data); } }
public void AddToBegining(int data) { if (headNode == null) { headNode = new SingleLinkNode(data); } else { SingleLinkNode temp = new SingleLinkNode(data); temp.next = headNode; headNode = temp; } }
public int getMax() { int max = this.data; SingleLinkNode current = next; while (current != null) { if (current.data > max) { max = current.data; } current = current.next; } return(max); }
public void AddSorted(int data) { if (headNode == null) { headNode = new SingleLinkNode(data); } else if (data < headNode.data) { AddToBegining(data); } else { headNode.AddSorted(data); } }
public void AddSorted(int data) { if (next == null) { next = new SingleLinkNode(data); } else if (data < next.data) { SingleLinkNode temp = new SingleLinkNode(data); temp.next = this.next; this.next = temp; } else { next.AddSorted(data); } }
public void reverse() { if (headNode == null) { return; } SingleLinkNode prev = null; SingleLinkNode current = headNode; SingleLinkNode next = current.next; while (next != null) { current.next = prev; prev = current; current = next; next = current.next; } headNode = prev; AddToBegining(current.data); }
public SingleLinkNode(int data) { this.data = data; next = null; }
public LinkedList() { headNode = null; }