コード例 #1
0
        public void InsertInEmptyList(int data)
        {
            Node temp = new Node(data);

            last = temp;
            last.link = last;
        }
コード例 #2
0
        public void Concatenate(CircularLinkedList list)
        {
            if (last == null)
            {
                last = list.last;
                return;
            }

            if (list.last == null)
            {
                return;
            }

            Node p = last.link;
            last.link = list.last.link;
            list.last.link = p;
            last = list.last;

        }
コード例 #3
0
        public void InsertInBeginning(int data)
        {
            Node temp = new Node(data);

            temp.link = last.link;
            last.link = temp;
        }
コード例 #4
0
        internal void DeleteLastNode()
        {
            // List is empty
            if (last == null)
            {
                return;
            }
            // The List has only one Node
            if (last.link == last)
            {
                last = null;
                return;
            }

            Node p = last.link;
            while (p.link != last)
            {
                p = p.link;
            }

            p.link = last.link;
            last =p;
        }
コード例 #5
0
        internal void DeleteNode(int x)
        {
            // List is empty
            if (last == null)
            {
                return;
            }

            //Deletion of only one Note
            if (last.link == last && last.info == x)
            {
                last = null;
                return;
            }

            //Deletion of the first node.
            if (last.link.info == x)
            {
                last.link = last.link.link;
                return;
            }

            Node p = last.link;

            while (p.link != last.link)
            {
                if (p.link.info == x)
                {
                    break;
                }

                p = p.link;
            }

            if (p.link == last.link)
            {
                Console.WriteLine(x + "not found in the list.");
            }

            else
            {
                p.link = p.link.link;

                if (last.info == x)
                {
                    last = p;
                }
            }
        }
コード例 #6
0
        internal void DeleteFirstNode()
        {
            // the list is empty
            if (last == null)
            {
                return;
            }

            // the list has only one Node.
            if (last.link == last)
            {
                last = null;
                return;
            }

            last.link = last.link.link;
        }
コード例 #7
0
 public CircularLinkedList()
 {
     last = null;
 }
コード例 #8
0
        public void InsertAfter(int data,int x)
        {
            Node p = last.link;

            do
            {
                if (p.info == x)
                {
                    break;
                }

                p = p.link;
            } while (p != last.link);

            if (p == last.link && p.info != x)
            {
                Console.WriteLine(x + " not present in the list<> ");
            }

            else
            {
                Node temp = new Node(data);

                temp.link = p.link;
                p.link = temp;

                if (p == last)
                {
                    last = temp;
                }
            }
        }
コード例 #9
0
        public void InsertAtEnd(int data)
        {
            Node temp = new Node(data);

            temp.link = last.link;
            last.link = temp;
            last = temp;
        }
コード例 #10
0
 public Node(int i)
 {
     info = i;
     link = null;
 }