Exemple #1
0
        internal void InsertAtPosition(int position, int item)
        {
            int listCount = DisplayListCount();

            if (listCount <= position)
            {
                int k = 0;
                p = start;
                while (p.link != null)
                {
                    k++;
                    if (k == position)
                    {
                        break;
                    }
                    p = p.link;
                }
                if (p.link == null)
                {
                    InsertAtEnd(item);
                    return;
                }
                NodeLink temp = new NodeLink(item);
                temp.link = p.link;
                p.link    = temp;
            }
            else
            {
                Console.WriteLine("You can insert till position " + listCount);
            }
        }
Exemple #2
0
        internal void InsertAfterNode(int itemCheckInsertAfterNode, int item)
        {
            p = start;
            while (p != null)
            {
                if (Convert.ToInt32(p.data) == itemCheckInsertAfterNode)
                {
                    break;
                }
                p = p.link;
            }

            if (p.data != null && p.link == null)
            {
                InsertAtEnd(item);
                return;
            }
            else
            {
                if (p.link == null)
                {
                    Console.WriteLine("No item foruns in list!");
                    return;
                }
                NodeLink temp = new NodeLink(item);
                temp.link = p.link;
                p.link    = temp;
            }
        }
Exemple #3
0
        internal void InsertAtBeginning(int item)
        {
            NodeLink temp = new NodeLink(item);

            temp.link = start;
            start     = temp;
        }
Exemple #4
0
        internal void BubbleSortListAddressOrLinkExcahnge()
        {
            NodeLink q, end, temp, r;

            for (end = null; end != start.link; end = p)
            {
                for (r = p = start; p.link != end; p = p.link)
                {
                    q = p.link;
                    if (Convert.ToInt32(p.data) > Convert.ToInt32(q.data))
                    {
                        p.link = q.link;
                        q.link = p;
                        if (p != start)
                        {
                            r.link = q;
                        }
                        else
                        {
                            start = q;
                        }
                        temp = p;
                        p    = q;
                        q    = temp;
                    }
                }
            }
        }
Exemple #5
0
 internal void DeleteLastNode()
 {
     p = start;
     while (p.link != null)
     {
         p = p.link;
     }
     p.link = null;
 }
Exemple #6
0
        public NodeLink reverseListRecursive(NodeLink x)
        {
            if (x == null || x.link == null)
            {
                return(x);
            }
            NodeLink temp = reverseListRecursive(x.link);

            x.link.link = x;
            x.link      = null;
            return(temp);
        }
Exemple #7
0
        internal void ReverseList()
        {
            NodeLink prev, next;

            prev = null;
            p    = start;
            while (p != null)
            {
                next   = p.link;
                p.link = prev;
                prev   = p;
                p      = next;
            }
            start = prev;
        }
Exemple #8
0
 internal void DisplayList()
 {
     if (CheckEmptyList())
     {
         return;
     }
     p = start;
     Console.Write("Items into list :");
     while (p != null)
     {
         Console.Write(p.data + " ");
         p = p.link;
     }
     Console.WriteLine("");
 }
Exemple #9
0
        internal void InsertAtEnd(int item)
        {
            NodeLink temp = new NodeLink(item);

            if (start == null)
            {
                temp.link = start;
                start     = temp;
                return;
            }
            p = start;
            while (p.link != null)
            {
                p = p.link;
            }
            p.link = temp;
        }
Exemple #10
0
        internal void BubbleSortListData()
        {
            NodeLink q, end;

            for (end = null; end != start.link; end = p)
            {
                for (p = start; p.link != end; p = p.link)
                {
                    q = p.link;
                    if (Convert.ToInt32(p.data) > Convert.ToInt32(q.data))
                    {
                        int temp = Convert.ToInt32(p.data);
                        p.data = q.data;
                        q.data = temp;
                    }
                }
            }
        }
Exemple #11
0
        internal int DisplayListCount()
        {
            int count = 0;

            if (CheckEmptyList())
            {
                return(count);
            }
            p = start;
            while (p.link != null)
            {
                count++;
                p = p.link;
            }
            int finalCount = count++;

            Console.WriteLine("Count :" + finalCount);
            return(finalCount);
        }
Exemple #12
0
        internal void InsertBeforeNode(int itemBeforeNode, int item)
        {
            p = start;
            while (p != null)
            {
                if (Convert.ToInt32(p.link.data) == itemBeforeNode)
                {
                    break;
                }
                p = p.link;
            }
            if (p.link == null)
            {
                Console.WriteLine("No item foruns in list!");
                return;
            }
            NodeLink temp = new NodeLink(item);

            temp.link = p.link;
            p.link    = temp;
        }
Exemple #13
0
        internal void CheckCyle(int cycleItem = 0)
        {
            Console.WriteLine("Check Cycle");
            if (start == null)
            {
                Console.WriteLine("List is empty");
                return;
            }
            NodeLink slowPointer = start, fastPointer = start;
            int      count = 0;

            while (fastPointer != null && fastPointer.link != null)
            {
                slowPointer = slowPointer.link;
                fastPointer = fastPointer.link.link;
                count++;
                if (slowPointer == fastPointer)
                {
                    Console.WriteLine("List has cycle as first point met to other pointer" + slowPointer.data);
                    if (cycleItem == 1)
                    {
                        Console.WriteLine("You can write code to insert NodeLink here");
                    }
                    else if (cycleItem == 2)
                    {
                        Console.WriteLine("You can write code to delete NodeLink here");
                    }
                    else if (cycleItem == 3)
                    {
                        Console.WriteLine("You can write code to udpate NodeLink here");
                    }
                    return;
                }
            }
            Console.WriteLine("List Don't have cycle");
            Console.WriteLine("Create Cycle mually for testing");
            start.link.link.link = start.link;
            CheckCyle();
        }
Exemple #14
0
 internal void DeleteOnlyNode(int deleteatposition)
 {
     if (deleteatposition == 0)
     {
         start = null;
     }
     else
     {
         int position = 0;
         p = start;
         while (p.link != null)
         {
             position++;
             if (position == deleteatposition)
             {
                 break;
             }
             p = p.link;
         }
         p.link = p.link.link;
     }
 }
Exemple #15
0
 public NodeLink(object i)
 {
     data = i;
     link = null;
 }
Exemple #16
0
 internal void DeleteFirstNode()
 {
     p     = start;
     start = p.link;
 }