Exemplo n.º 1
0
        internal static void DeleteNodeDoubly(DList list, int data)
        {
            DNode node = list.head;

            while (node.data != data)
            {
                node = node.next;
            }
            node.prev.next = node.next;
            node.next.prev = node.prev;
        }
Exemplo n.º 2
0
        internal static void InsertFrontDoubly(DList list, int data)
        {
            DNode newNode = new DNode(data);

            if (list.head != null)
            {
                list.head.prev = newNode;
            }
            newNode.next = list.head;
            newNode.prev = null;
            list.head    = newNode;
        }
Exemplo n.º 3
0
        internal static void PrintAllDoubly(DList list)
        {
            DNode node = list.head;

            Console.WriteLine("Doubly Linked List:");
            while (node.next != null)
            {
                Console.Write(node.data + " ");
                node = node.next;
            }
            Console.Write(node.data);
            Console.WriteLine();
        }
Exemplo n.º 4
0
        internal static void InsertBackDoubly(DList list, int data)
        {
            DNode newNode = new DNode(data);
            DNode node    = list.head;

            while (node.next != null)
            {
                node = node.next;
            }

            node.next    = newNode;
            newNode.prev = node;
            newNode.next = null;
        }
Exemplo n.º 5
0
        internal static void InsertNextToDoubly(DList list, DNode prev, int data)
        {
            DNode prevNode = list.head;
            DNode node     = new DNode(data);

            while (prevNode.data != prev.data)
            {
                prevNode = prevNode.next;
            }

            node.prev          = prevNode;
            node.next          = prevNode.next;
            prevNode.next      = node;
            prevNode.next.prev = node;
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            //var linkedList = new LinkedList<int>();

            SList singleList = new SList();
            DList doubleList = new DList();

            //Queue q = new Queue();
            //Stack s = new Stack();

            InsertFrontSingly(singleList, 5);
            InsertFrontSingly(singleList, 10);
            InsertFrontSingly(singleList, 15);
            InsertFrontSingly(singleList, 20);
            InsertFrontSingly(singleList, 25);

            //PrintAllSingly(singleList);
            //DeleteNodeSingly(singleList, 20);
            //PrintAllSingly(singleList);

            PrintAllSingly(singleList);
            ReverseSingly(singleList);
            PrintAllSingly(singleList);

            InsertFrontDoubly(doubleList, 5);
            InsertFrontDoubly(doubleList, 10);
            InsertFrontDoubly(doubleList, 15);
            InsertFrontDoubly(doubleList, 20);
            InsertFrontDoubly(doubleList, 25);

            //PrintAllDoubly(doubleList);
            //DeleteNodeDoubly(doubleList, 20);
            //PrintAllDoubly(doubleList);

            Console.ReadLine();
        }