예제 #1
0
 public void Search()
 {
     LinkedlList.Node n = l.headNode;
     if (n == null)
     {
         Console.WriteLine("The list is empty.");
     }
     else
     {
         Console.WriteLine("Please enter the element to be searched");
         int elem  = Convert.ToInt32(Console.ReadLine());
         int count = 0;
         while (n.next != null)
         {
             if (n._data == elem)
             {
                 Console.WriteLine("Element found at position {0}", count);
                 break;
             }
             else if (n.next._data == elem)
             {
                 Console.WriteLine("Element found at position {0}", count + 1);
                 break;
             }
             else
             {
                 n = n.next;
                 count++;
             }
         }
     }
 }
예제 #2
0
        public LinkedlList.Node GetLastNode()
        {
            LinkedlList.Node n = l.headNode;
            while (n.next != null)
            {
                n = n.next;
            }

            return(n);
        }
예제 #3
0
 public void Display()
 {
     LinkedlList.Node n = l.headNode;
     if (n == null)
     {
         Console.WriteLine("The list is empty");
     }
     while (n != null)
     {
         Console.Write("{0}  ", n._data);
         n = n.next;
     }
 }
예제 #4
0
        public void InsertAtFirst()
        {
            LinkedlList.Node n = l.headNode;
            Console.WriteLine("Please enter the element to be inserted");
            int elem = Convert.ToInt32(Console.ReadLine());

            LinkedlList.Node newnode = new LinkedlList.Node(elem);
            if (n == null)
            {
                l.headNode = newnode;
            }
            else
            {
                newnode.next = n;
                l.headNode   = newnode;
            }
        }
예제 #5
0
        public void Delete()
        {
            LinkedlList.Node n = l.headNode;
            if (n == null)
            {
                Console.WriteLine("The list is empty.");
            }
            else
            {
                Console.WriteLine("Please enter the element to be deleted");
                int elem = Convert.ToInt32(Console.ReadLine());
                LinkedlList.Node next = null;
                LinkedlList.Node prev = null;
                if (n != null && n._data == elem)
                {
                    l.headNode = n.next;
                }

                int d = 2 ^ 10;

                while (n.next != null)
                {
                    if (n.next._data == elem)
                    {
                        prev = n;
                    }
                    if (n._data == elem)
                    {
                        next = n.next;
                    }

                    n = n.next;
                }
                if (prev != null)
                {
                    prev.next = next;
                }
            }
        }