Пример #1
0
 public void Reverse()
 {
     if (Head == null)
     {
         Console.WriteLine("there aren't any nodes in the list!");
     }
     else
     {
         DLLNode runner = Head;
         while (runner.Next != null)
         {
             runner = runner.Next;
         }
         DLLNode start = runner;
         runner.Next = runner.Prev;
         runner.Prev = null;
         while (runner.Next != Head)
         {
             DLLNode temp = runner.Next;
             temp.Next = temp.Prev;
             temp.Prev = runner;
             runner    = temp;
         }
         Head.Prev = runner;
         Head.Next = null;
         Head      = start;
     }
 }
Пример #2
0
 public void PrintValues()
 {
     if (Head == null)
     {
         Console.WriteLine("there isn't a list!");
     }
     else
     {
         DLLNode runner = Head;
         while (runner.Next != null)
         {
             Console.WriteLine(runner.Value);
             runner = runner.Next;
         }
         Console.WriteLine(runner.Value);
     }
 }
Пример #3
0
        public void Add(int value)
        {
            DLLNode newNode = new DLLNode(value);

            if (Head == null)
            {
                Head = newNode;
            }
            else
            {
                DLLNode runner = Head;
                while (runner.Next != null)
                {
                    runner = runner.Next;
                }
                runner.Next  = newNode;
                newNode.Prev = runner;
            }
        }
Пример #4
0
 public void Remove(int value)
 {
     if (Head == null)
     {
         Console.WriteLine("there aren't any nodes in the list!");
     }
     else
     {
         if (Head.Value == value)
         {
             if (Head.Next == null)
             {
                 Head = null;
             }
             else
             {
                 Head      = Head.Next;
                 Head.Prev = null;
             }
         }
         else
         {
             DLLNode runner = Head;
             while (runner.Next.Next != null)
             {
                 if (runner.Next.Value == value)
                 {
                     runner.Next           = runner.Next.Next;
                     runner.Next.Next.Prev = runner;
                     break;
                 }
                 runner = runner.Next;
             }
         }
     }
 }
Пример #5
0
 public DoublyLinkedList()
 {
     Head = null;
 }
Пример #6
0
 public DLLNode(int val)
 {
     Value = val;
     Next  = null;
     Prev  = null;
 }