using for insert next node and return

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace DoubluLinkedList{    class Program    {        class ProgramDLinkedList        {            private int data; /*Declare class value members*/            private ProgramDLinkedList next; /*Declare class value members*/            private ProgramDLinkedList prev; /*Declare class value members*/            public ProgramDLinkedList() /*Constructor of ProgramDLinkedList Class*/            {                data = 0; /*Initialize class value members*/                next = null; /*Initialize class value members*/                prev = null; /*Initialize class value members*/            }            public ProgramDLinkedList(int value)/*second Constructor of ProgramDLinkedList Class with parameter value*/            {                data = value; /*Initialize class value members*/                next = null; /*Initialize class value members*/                prev = null; /*Initialize class value members*/            }            public ProgramDLinkedList InsertNext(int value) /*Creat a Function for insert next node and return object of same class.*/            {                ProgramDLinkedList node = new ProgramDLinkedList(value); /*Creating Object*/                if (this.next == null)                {                    node.prev = this;/*early set in constructor*/                    node.next = null; /*Early null value*/                    this.next = node; /*Assign Object to next node*/                }                else                {                    /*Insert in mid of the list*/                    ProgramDLinkedList temp = this.next; /*make temporary object of same class and assign next node object to temporary object */                    node.prev = this; /*Seeting Previous value*/                    node.next = temp;/*Setting Next value of node*/                    this.next = node;/*Setting Previous value*/                    temp.prev = node;/*Setting prev value of temporary object*/                    /*temp.next does not have to be changed*/                }                return node; /*Return object*/            }            public ProgramDLinkedList InsertPrev(int value) /*Creat a Function for Previous next node and return object of same class.*/            {                ProgramDLinkedList node = new ProgramDLinkedList(value);/*Creating Object*/                if (this.prev == null)                {                    node.prev = null;/*early set Null*/                    node.next = this;/*early set in constructor*/                    this.prev = node;/*Assign Object to Prev node*/                }                else                {                    /*Insert in mid of the list*/                    ProgramDLinkedList temp = this.prev;/*make temporary object of same class and assign next node object to temporary object */                    node.prev = temp;/*Setting Next value of node*/                    node.next = this;/*Setting Next value of node*/                    this.prev = node;/*Setting Previous value*/                    temp.next = node;/*Setting Next value of node*/                    // temp.prev does not have to be changed                }                return node;/*Return object*/            }            public void TraverseFront() /*Function for show record in front form*/            {                TraverseFrontEnd(this);            }            public void TraverseFrontEnd(ProgramDLinkedList node)/*Function for show record in front form*/            {                if (node == null)                    node = this; /*Setting value of current object*/                System.Console.WriteLine(”

Traversing in Forward Direction

We Will Write a Custom Essay Specifically
For You For Only $13.90/page!


order now

“); /*Print The Message*/                while (node != null)                {                    System.Console.WriteLine(node.data); /*Printing each node*/                    node = node.next; /*Setting next node to print*/                }            }            public void TraverseBack()/*Function for show record in back form*/            {                TraverseBackEnd(this);            }            public void TraverseBackEnd(ProgramDLinkedList node)            {                if (node == null)                    node = this;/*Setting value of current object*/                System.Console.WriteLine(”

Traversing in Backward Direction

“);/*Print The Message*/                while (node != null)                {                    System.Console.WriteLine(node.data);/*Printing each node*/                    node = node.prev;/*Setting prev node to print*/                }                Console.ReadLine();            }            static void Main(string args)            {                ProgramDLinkedList node1 = new ProgramDLinkedList(1); /*Object of class with parameterize constructor*/                ProgramDLinkedList node3 = node1.InsertNext(3); /*Insert Record*/                ProgramDLinkedList node2 = node3.InsertPrev(2); /*Insert Record*/                ProgramDLinkedList node5 = node3.InsertNext(5);/*Insert Record*/                ProgramDLinkedList node4 = node5.InsertPrev(4);/*Insert Record*/                node1.TraverseFront();/*Geting pront*/                node5.TraverseBack();/*Geting Prev*/            }        }     }}