static void Main(string[] args) { CircularLinkedList <int> list = new CircularLinkedList <int>(); list.PushFirst(10); list.PushFirst(20); list.PushFirst(30); Node <int> temp = list.head; do { Console.Write(temp.data + "-->"); temp = temp.next; }while (temp != list.head); Console.WriteLine("\n" + list.length); Console.Write(""); Console.ReadKey(); }
static void Main(string[] args) { Data d1 = new SubDataFirst(123, "FirstNode"); Data d2 = new SubDataFirst(456, "SecondNode"); Data d3 = new SubDataFirst(789, "ThirdNode"); Data d4 = new SubDataFirst(56, "FourthNewNode"); Data d5 = new SubDataFirst(57, "FifthNewNode"); Node First_Node = new Node(d1); Node Second_Node = new Node(d2); Node Third_Node = new Node(d3); Node Fourth_Node = new Node(d4); Node Fifth_Node = new Node(d5); /*************Single Linked List***************/ SingleLinkedList singleLinkedList = new SingleLinkedList(); singleLinkedList.Head = First_Node; /*Setting the first node*/ singleLinkedList.Head.Next = Second_Node; Second_Node.Next = Third_Node; Third_Node.Next = null; singleLinkedList.Display(); singleLinkedList.InsertNewNodeAtFrontOfLinkedList(Fourth_Node); singleLinkedList.Display(); singleLinkedList.InsertNewNodeAtEndOfLinkedList(Fifth_Node); singleLinkedList.Display(); /*************Circular Linked List***************/ CircularLinkedList circularLinkedList = new CircularLinkedList(); circularLinkedList.InsertNewNodeAtFrontOfLinkedList(First_Node); circularLinkedList.InsertNewNodeAtFrontOfLinkedList(Second_Node); circularLinkedList.InsertNewNodeAtFrontOfLinkedList(Third_Node); circularLinkedList.InsertNewNodeAtFrontOfLinkedList(Fourth_Node); circularLinkedList.InsertNewNodeAtFrontOfLinkedList(Fifth_Node); circularLinkedList.Display(); }
static void Main(string[] args) { var circularList = new CircularLinkedList <int>(); circularList.Add(1); circularList.Add(2); circularList.Add(3); circularList.Add(4); circularList.Add(5); foreach (var item in circularList) { Console.WriteLine(item); } Console.WriteLine(); circularList.Delete(3); foreach (var item in circularList) { Console.WriteLine(item); } Console.WriteLine(); Console.WriteLine(); var duplexList = new DuplexLinkedList <int>(); duplexList.Add(10); duplexList.Add(20); duplexList.Add(30); duplexList.Add(40); duplexList.Add(50); duplexList.Add(60); duplexList.Add(70); foreach (var item in duplexList) { Console.WriteLine(item); } Console.WriteLine(); duplexList.Delete(40); foreach (var item in duplexList) { Console.WriteLine(item); } Console.WriteLine(); foreach (var item in duplexList.Reverse()) { Console.WriteLine(item); } Console.WriteLine(); var list = new Model.LinkedList <int>(); list.Add(1); list.Add(2); list.Add(3); list.Add(4); list.Add(5); foreach (var item in list) { Console.Write(item + " \t"); } Console.WriteLine(); list.Delete(3); list.Delete(1); list.Delete(7); foreach (var item in list) { Console.Write(item + " \t"); } Console.WriteLine(); list.AppendHead(9); foreach (var item in list) { Console.Write(item + " \t"); } Console.WriteLine(); list.InsertAfter(4, 8); foreach (var item in list) { Console.Write(item + " \t"); } Console.WriteLine(); Console.ReadKey(); }
static void Main(string[] args) { Console.WriteLine("CircularLinkedList:"); var circularList = new CircularLinkedList <int>(); circularList.Add(1); circularList.Add(2); circularList.Add(3); circularList.Add(4); circularList.Add(5); foreach (var item in circularList) { Console.Write($"{item} "); } Console.WriteLine("\nCircularLinkedList -> Delete"); circularList.Delete(3); foreach (var item in circularList) { Console.Write($"{item} "); } Console.WriteLine("\n\nDuplexLinkedList:"); var duplexList = new DuplexLinkedList <int>(); duplexList.Add(1); duplexList.Add(2); duplexList.Add(3); duplexList.Add(4); duplexList.Add(5); foreach (var item in duplexList) { Console.Write($"{item} "); } Console.WriteLine("\nDuplexLinkedList -> Delete:"); duplexList.Delete(3); foreach (var item in duplexList) { Console.Write($"{item} "); } Console.WriteLine("\nDuplexLinkedList -> Reverse:"); var reverseDuplexList = duplexList.Reverse(); foreach (var item in reverseDuplexList) { Console.Write($"{item} "); } Console.WriteLine("\n\nLinkedList:"); var list = new Model.LinkedList <int>(); list.Add(1); list.Add(2); list.Add(3); list.Add(4); list.Add(5); foreach (var item in list) { Console.Write($"{item} "); } Console.WriteLine("\nLinkedList -> Delete:"); list.Delelete(3); list.Delelete(1); list.Delelete(7); foreach (var item in list) { Console.Write($"{item} "); } Console.WriteLine("\nLinkedList -> AppendHead:"); list.AppendHead(7); foreach (var item in list) { Console.Write($"{item} "); } Console.WriteLine("\nLinkedList -> InsertAfter:"); list.InsertAfter(4, 8); foreach (var item in list) { Console.Write($"{item} "); } Console.ReadLine(); }
static void Main(string[] args) { var circularList = new CircularLinkedList <int>(); circularList.Add(1); circularList.Add(2); circularList.Add(3); circularList.Add(4); circularList.Add(5); foreach (var item in circularList) { Console.WriteLine(item); } circularList.Delete(2); foreach (var item in circularList) { Console.WriteLine(item); } Console.WriteLine(); Console.ReadLine(); var duplexList = new DuplexLinkedList <int>(); duplexList.Add(1); duplexList.Add(2); duplexList.Add(3); duplexList.Add(4); duplexList.Add(5); foreach (var item in duplexList) { Console.WriteLine(item); } duplexList.Delete(3); foreach (var item in duplexList) { Console.WriteLine(item); } Console.WriteLine(); var reverse = duplexList.Reverse(); foreach (var item in reverse) { Console.WriteLine(item); } Console.ReadLine(); var list = new Model.LinkedList <int>(); list.Add(1); list.Add(2); list.Add(3); list.Add(4); list.Add(5); foreach (var item in list) { Console.Write(item + " "); } Console.WriteLine(); list.Delete(3); list.Delete(1); list.Delete(9); foreach (var item in list) { Console.Write(item + " "); } Console.WriteLine(); list.AppendHead(7); foreach (var item in list) { Console.Write(item + " "); } Console.WriteLine(); list.InsertAfter(2, 8); foreach (var item in list) { Console.Write(item + " "); } Console.WriteLine(); Console.ReadLine(); }
static void Main(string[] args) { var list = new Model.LinkedList <int>(); list.Add(1); list.Add(2); list.Add(3); list.Add(4); list.Add(5); foreach (var item in list) { Console.Write(item + " "); } list.Delete(3); list.Delete(1); Console.Write("\nAfter removing items: "); foreach (var item in list) { Console.Write(item + " "); } list.AppendHead(10); Console.Write("\nAfter adding an element to the begining: "); foreach (var item in list) { Console.Write(item + " "); } list.InsertAfter(4, 8); Console.Write("\nAfter adding an element after some element: "); foreach (var item in list) { Console.Write(item + " "); } Console.ReadLine(); var duplexList = new DuplexLinkedList <int>(); duplexList.Add(1); duplexList.Add(2); duplexList.Add(3); duplexList.Add(4); duplexList.Add(5); Console.Write("Duplex linked list: "); foreach (var item in duplexList) { Console.Write(item + " "); } duplexList.Delete(3); Console.Write("\nDuplex linked list after removing element: "); foreach (var item in duplexList) { Console.Write(item + " "); } var reverseDLL = duplexList.Reverse(); Console.Write("\nDuplex linked list after reversal: "); foreach (var item in reverseDLL) { Console.Write(item + " "); } Console.ReadLine(); var circularList = new CircularLinkedList <int>(); circularList.Add(1); circularList.Add(2); circularList.Add(3); circularList.Add(4); circularList.Add(5); Console.Write("Circular linked list: "); foreach (var item in circularList) { Console.Write(item + " "); } Console.Write("\nCircular linked list after delete item: "); circularList.Delete(3); foreach (var item in circularList) { Console.Write(item + " "); } }