Beispiel #1
0
 public DoubleLinkedList()
 {
     data = 0;
     next = null;
     prev = null;
 }
Beispiel #2
0
 public DoubleLinkedList(int value)
 {
     data = value;
     next = null;
     prev = null;
 }
Beispiel #3
0
        static void Main(string[] args)
        {
            DoubleLinkedList              dll   = new DoubleLinkedList();
            IUndoable <DoubleLinkedList>  test  = new Undoable <DoubleLinkedList>(dll);
            IUndoState <DoubleLinkedList> state = new UndoState <DoubleLinkedList>(dll);

            DoubleLinkedList stateList(DoubleLinkedList node)
            {
                DoubleLinkedList res = new DoubleLinkedList();

                while (node != null)
                {
                    res.Insertion(node.data);
                    node = node.next;
                }
                return(res);
            }

            //1: initial double linkedlist with {5,3,2,1,4,8} and print it out
            dll.Insertion(5);
            dll.Insertion(3);
            dll.Insertion(2);
            dll.Insertion(1);
            dll.Insertion(4);
            dll.Insertion(8);
            test.Value = stateList(dll.head);
            test.SaveState();
            Console.Write("The initial list is: ");
            dll.PrintList(dll.head);
            Console.Write("The current state is: ");
            state.printState();


            //2: bubble sort the original list and print it out
            dll.Sort(dll.head);
            test.Value = stateList(dll.head);
            Console.Write("\nThe sorted list is: ");
            dll.PrintList(dll.head);
            test.SaveState();
            Console.Write("The current state is: ");
            state.printState();

            //3: reverse the list
            dll.Reverse();
            test.Value = stateList(dll.head);
            Console.Write("\nThe reverse list is: ");
            dll.PrintList(dll.head);
            test.SaveState();
            Console.Write("The current state is: ");
            state.printState();

            //4: add 9 to the end of the list
            dll.Insertion(9);
            test.Value = stateList(dll.head);
            Console.Write("\nInsert 9 into list: ");
            dll.PrintList(dll.head);
            test.SaveState();



            //5: Undo back to before you reversed the list
            test.Undo();
            test.Undo();
            Console.Write("\nUndo back to before you reversed the list: ");
            dll.PrintList(dll.head);


            //6: Add a 9 to the end of the list again
            test.Redo();
            test.Redo();
            Console.Write("\nRedo add 9 to the end of list: ");
            dll.PrintList(dll.head);


            //7: Undo back to the original list
            test.Undo();
            test.Undo();
            test.Undo();
            Console.Write("\nUndo back to the original list: ");
            dll.PrintList(dll.head);
        }