예제 #1
0
 private void DeleteData()
 {
     if (info == "")
     {
         Console.WriteLine("No Data Present To Delete..\n Deletition couldn't be performed");
         Console.ReadKey();
     }
     else
     {
         TwoWayNode current = this;
         Console.Write("\nWhich Data You want to Delete : ");
         string cmp = Console.ReadLine();
         while ((current != null) && (current.info.ToLower().Equals(cmp.ToLower()) == false))
         {
             current = current.next;
         }
         if (current == null)
         {
             Console.WriteLine($"{cmp} Not Present..\n Deletition couldn't be performed");
             Console.ReadKey();
         }
         else if (current.prev == null)
         {
             this.DeleteFirst();
         }
         else
         {
             current.prev.next = current.next;
             //current = null;
         }
     }
 }
예제 #2
0
 private void DeleteLast()
 {
     if (info == "")
     {
         Console.WriteLine("No Data Present To Delete..\n Deletition couldn't be performed");
         Console.ReadKey();
     }
     else
     {
         TwoWayNode current = this;
         while (current.next != null)
         {
             current = current.next;
         }
         if (current.prev == null)
         {
             this.DeleteFirst();
         }
         else
         {
             current.prev.next = null;
             // current = null;
         }
     }
 }
예제 #3
0
        private void InsertFront()
        {
            Console.Write("Enter The Data You Want To Store : ");
            string ii;

            do
            {
                ii = Console.ReadLine();
            } while (ii == "");
            if (info == "")
            {
                info = ii;
            }
            else
            {
                TwoWayNode newNode = new TwoWayNode
                {
                    info = this.info,
                    next = this.next,
                    prev = this
                };
                this.info = ii;
                this.next = newNode;
            }
        }
예제 #4
0
        private void InsertLast()
        {
            Console.Write("Enter The Data You Want To Store : ");
            string ii;

            do
            {
                ii = Console.ReadLine();
            } while (ii == "");
            if (info == "")
            {
                info = ii;
            }
            else
            {
                TwoWayNode newNode = new TwoWayNode
                {
                    info = ii
                };
                TwoWayNode current = this;
                while (current.next != null)
                {
                    current = current.next;
                }
                current.next = newNode;
                newNode.prev = current;
            }
        }
예제 #5
0
        private void DisplayAll()
        {
            TwoWayNode current = this;

            Console.Write("Nodes :");
            if (info == "")
            {
                Console.WriteLine("   Empty Linear Node\n");
            }
            else
            {
                do
                {
                    Console.Write($"  {current.info}    ");
                    current = current.next;
                } while (current != null);
                Console.WriteLine("\n");
            }
        }
예제 #6
0
        private void InsertAfter()
        {
            Console.Write("Enter The Data You Want To Store : ");
            string ii;

            do
            {
                ii = Console.ReadLine();
            } while (ii == "");
            if (info == "")
            {
                Console.WriteLine("No Data present in the List..\n DATA NOT INSERTED");
                Console.ReadKey();
            }
            else
            {
                TwoWayNode newNode = new TwoWayNode
                {
                    info = ii
                };
                TwoWayNode current = this;
                Console.Write("\nAfter which Data You want to Store : ");
                String cmp = Console.ReadLine();
                while ((current != null) && (current.info.ToLower().Equals(cmp.ToLower()) == false))
                {
                    current = current.next;
                }
                if (current == null)
                {
                    Console.WriteLine($"{cmp} not found in Nodes..\n DATA NOT INSERTED");
                    Console.ReadKey();
                }
                else
                {
                    newNode.next      = current.next;
                    current.next      = newNode;
                    current.next.prev = newNode;
                    newNode.prev      = current;
                }
            }
        }
예제 #7
0
 private void DeleteFirst()
 {
     if (info == "")
     {
         Console.WriteLine("No Data Present To Delete..");
         Console.ReadKey();
     }
     else
     {
         TwoWayNode current = this.next;
         if (current == null)
         {
             this.info = "";
         }
         else
         {
             this.info = current.info;
             this.next = current.next;
             //current = null;
         }
     }
 }
예제 #8
0
 public TwoWayNode()
 {
     next = prev = null;
     info = "";
 }