Example #1
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;
                next = this;
            }
            else
            {
                CircularNode newNode = new CircularNode
                {
                    info = ii
                };
                CircularNode current = this;
                while (current.next != this)
                {
                    current = current.next;
                }
                current.next = newNode;
                newNode.next = this;
            }
        }
Example #2
0
 private void DeleteData()
 {
     if (info == "")
     {
         Console.WriteLine("No Data Present To Delete..\n Deletition couldn't be performed");
         Console.ReadKey();
     }
     else
     {
         CircularNode current = this.next;
         CircularNode parent  = this;
         Console.Write("\nWhich Data You want to Delete : ");
         String cmp = Console.ReadLine();
         while ((current != this) && (current.info.ToLower().Equals(cmp.ToLower()) == false))
         {
             parent  = current;
             current = current.next;
         }
         if (current == this && (current.info.ToLower().Equals(cmp.ToLower()) == true))
         {
             DeleteFirst();
         }
         else if (current == this)
         {
             Console.WriteLine($"{cmp} Not Present..\n Deletition couldn't be performed");
             Console.ReadKey();
         }
         else
         {
             parent.next = current.next;
             //current = null;
         }
     }
 }
Example #3
0
 private void DeleteLast()
 {
     if (info == "")
     {
         Console.WriteLine("No Data Present To Delete..\n Deletition couldn't be performed");
         Console.ReadKey();
     }
     else
     {
         CircularNode current = this;
         CircularNode parent  = null;
         while (current.next != this)
         {
             parent  = current;
             current = current.next;
         }
         if (parent == null)
         {
             this.DeleteFirst();
         }
         else
         {
             parent.next = this;
             //current = null;
         }
     }
 }
Example #4
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;
                next = this;
            }
            else
            {
                CircularNode newNode = new CircularNode
                {
                    info = this.info,
                    next = this.next
                };
                this.info = ii;
                this.next = newNode;
            }
        }
Example #5
0
        private void DisplayAll()
        {
            CircularNode current = this;

            Console.Write("Nodes :");
            if (info == "")
            {
                Console.WriteLine("   Empty Linear Node\n");
            }
            else
            {
                do
                {
                    Console.Write($"  {current.info}    ");
                    current = current.next;
                } while (current != this);
                Console.WriteLine("\n");
            }
        }
Example #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
            {
                CircularNode newNode = new CircularNode
                {
                    info = ii
                };
                CircularNode current = this.next;
                Console.Write("\nAfter which Data You want to Store : ");
                String cmp = Console.ReadLine();
                bool   CMP = new bool();
                while ((current != this) && (CMP = current.info.ToLower().Equals(cmp.ToLower()) == false))
                {
                    current = current.next;
                }
                if (current == this && CMP == false)
                {
                    Console.WriteLine($"{cmp} not found in Nodes..\n DATA NOT INSERTED");
                    Console.ReadKey();
                }
                else
                {
                    newNode.next = current.next;
                    current.next = newNode;
                }
            }
        }
Example #7
0
 private void DeleteFirst()
 {
     if (info == "")
     {
         Console.WriteLine("No Data Present To Delete..");
         Console.ReadKey();
     }
     else
     {
         CircularNode current = this.next;
         if (current == this)
         {
             this.info = "";
             this.next = null;
         }
         else
         {
             this.info = current.info;
             this.next = current.next;
             //current = null;
         }
     }
 }
Example #8
0
 public CircularNode()
 {
     next = null;
     info = "";
 }