Пример #1
0
 // 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;
     }
 }
Пример #2
0
 //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;
     }
 }
Пример #3
0
 //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;
     }
 }
Пример #4
0
 public void PrintBackwards(Node node)
 {
     if (node.next != null)
     {
         PrintBackwards(node.next);
         Console.WriteLine(node.data);
     }
     else
         Console.WriteLine(node.data);
 }
Пример #5
0
 // Constructs default list
 public LinkedList()
 {
     size = 0;
     _head = null;
     _tail = null;
 }
Пример #6
0
 public Node(Object n, Node m)
 {
     data = n;
     next = m;
 }
Пример #7
0
 public Node()
 {
     data = null;
     next = null;
 }
Пример #8
0
        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;
        }