// Add object to the front public void AddToFront(object item) { size++; var insert = new Node(item, null); if (_head == null) { _head = _tail = insert; } else { insert.next = _head; _head = insert; } }
//Delete and retrieve item from front public object DeleteFromFront() { Node item = new Node(); item = _head; if (_head == null) { return null; } else { _head.next = _head; return item; } }
//Add object to the back public void AddToBack(object item) { size++; var insert = new Node(item, null); if (_head == null) { _head = _tail = insert; } else { _tail.next = insert; _tail = insert; } }
public void PrintBackwards(Node node) { if (node.next != null) { PrintBackwards(node.next); Console.WriteLine(node.data); } else Console.WriteLine(node.data); }
// Constructs default list public LinkedList() { size = 0; _head = null; _tail = null; }
public Node(Object n, Node m) { data = n; next = m; }
public Node() { data = null; next = null; }
public void ReverseList(Node node) { if (node != null && node.next != null) { Node next = node.next; Node afterNext = node.next.next; Node currentHead = _head; _head = next; _head.next = currentHead; node.next = afterNext; ReverseList(node); } else _tail = node; }