Exemplo n.º 1
0
    static void Main()
    {
        Linkedlist l1 = new Linkedlist();

        l1.AddFirst(3);
        l1.AddFirst(2);
        l1.AddFirst(6);
        l1.AddFirst(5);
        l1.AddFirst(11);
        l1.AddFirst(10);
        l1.AddFirst(15);
        l1.AddFirst(12);
        //l1.head= l1.reverseAlternateBySize(l1.head,3,true);
        //l1.deleteNodesWithLessValue(l1.head);
        l1.segregateEvenAndOdd(ref l1.head);
        l1.printwithnode(l1.head);
        //l1.printList();
        //l1.printList();
        // int size=l1.getIterativeCount();
        // Linkedlist l2= new Linkedlist();
        // l2.head=l1.IterativeReverse();
        // for(int i=0;i<size;i++)
        // {
        //  Node head1=l1.head,head2=l2.head;
        //  if(head1.data!=head2.data)
        //  {
        //      Console.WriteLine("Not Palindrome");
        //      break;
        //  }
        //  head1=head1.next;
        //  head2=head2.next;
        // }
        // l1.printList();
    }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            //Arraylist a = new Arraylist (new int[] { 8,4,4 });
            // Arraylist AAA = new Arraylist();
            //  int[] prosto = new int[] {9,3 } ;
            // int[] q = AAA.AddattheEnd(2);
            // Console.Write(q);
            //  a.Addatthebeginning(prosto);
            //  a.Readscreen();
            //  a.Addbyindex(1, 7);
            //a.AccessByValue(2);
            //a.sortingDown();
            Linkedlist L = new Linkedlist(new int[] { 8, 4, 4 });

            L[0] = 5;

            for (int i = 0; i < L.returnlenght(); i++)
            {
                Console.Write(L[i] + " ");
            }
            // L.Addbyindex(0, 9);
            //L.AddattheEnd(1);
            //vuvod(L.Returnmassiv());
            //L.AddattheEnd(2);
            //vuvod(L.Returnmassiv());
            //L.AddattheEnd(3);
            //vuvod(L.Returnmassiv());
            //L.AddattheEnd(4);
            //vuvod(L.Returnmassiv());
        }
Exemplo n.º 3
0
 static void Main(string[] args)
 {
     Linkedlist list = new Linkedlist();
     list.Add("test1");
     list.Add("test2");
     list.Add(1, "test3");
 }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            int size               = 0;
            int nodevalue          = 0;
            int n                  = 0;
            Linkedlist <int> llist = new Linkedlist <int>();

Sizecheck:
            try
            {
                Console.WriteLine("Enter the no. of nodes of Linked list:");
                size = int.Parse(Console.ReadLine());
                while (size <= 0)
                {
                    Console.WriteLine("Enter valid size:");
                    size = int.Parse(Console.ReadLine());
                }
            }
            catch (FormatException e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine("Enter the correct size:");
                goto Sizecheck;
            }
            for (int i = 0; i < size; i++)
            {
                Console.WriteLine("Enter the integer node value:");
nodevalue:
                try
                {
                    nodevalue = int.Parse(Console.ReadLine());
                }
                catch (FormatException e)
                {
                    Console.WriteLine(e.Message);
                    goto nodevalue;
                }
                llist.node_Addition(nodevalue);
            }
            llist.node_Traverse();
compute_n:
            try
            {
                Console.WriteLine("\nEnter the number of node to fetch from last: ");
                n = int.Parse(Console.ReadLine());
                while (n < 1 || n > size)
                {
                    Console.WriteLine("Enteres value is out of range:");
                    n = int.Parse(Console.ReadLine());
                }
            }
            catch (FormatException e)
            {
                Console.WriteLine(e.Message);
                goto compute_n;
            }
            llist.computeNthNodefromLast(n);
        }
 public static void Main(string[] args)
 {
     Linkedlist l1=new Linkedlist();
     l1.addNode(1);
     l1.addNode(2);
     l1.addNode(3);
     l1.addNode(4);
     l1.addNode(5);
     l1.print();
 }
Exemplo n.º 6
0
    static void Main()
    {
        Linkedlist l1 = new Linkedlist();

        l1.addLastWithTail(1);
        l1.addLastWithTail(5);
        l1.addLastWithTail(7);
        l1.addLastWithTail(9);
        l1.changenext(ref l1.head);
        l1.printList();
    }
    public static void Main(string[] args)
    {
        Linkedlist l1 = new Linkedlist();

        l1.addNode(1);
        l1.addNode(2);
        l1.addNode(3);
        l1.addNode(4);
        l1.addNode(5);
        l1.print();
    }
    static void Main()
    {
        Linkedlist l1 = new Linkedlist();

        l1.addLastWithTail(1);
        l1.addLastWithTail(9);
        l1.addLastWithTail(4);
        l1.addLastWithTail(2);
        //l1.addLastWithTail(3);
        //l1.addLastWithTail(5);
        l1.mergesort(ref l1.head);
        l1.printwithnode(l1.head);
    }
    static void Main()
    {
        Linkedlist l1 = new Linkedlist();

        l1.addLastWithTail(1);
        l1.addLastWithTail(5);
        l1.addLastWithTail(7);
        l1.addLastWithTail(9);
        Linkedlist l2 = new Linkedlist();

        l2.addLastWithTail(1);
        l2.addLastWithTail(5);
        l2.addLastWithTail(7);
        l2.addLastWithTail(11);
        if (l1.recursiveAreIdentical(l1.head, l2.head))
        {
            Console.WriteLine("Identical");
        }
        else
        {
            Console.WriteLine("not");
        }
        //Linkedlist l3=new Linkedlist();
        //l3.sortedMerge(l1.head,l2.head);
        //l3.head= l3.recursiveSortedMerge(l1.head,l2.head);
        //Linkedlist l3=new Linkedlist();
        //l1.alternateSplit(l1.head,l2,l3);
        //l3.printList();
        //Console.WriteLine("next");
        //l3.printList();
        //l1.AddLast(1);
        //l1.AddLast(2);
        //l1.AddLast(3);
        //l1.AddLast(4);
        //l1.insertAfter(l1.head.next.next,8);
        //l1.insertBefore(l1.head.next,9);
        //l1.printList();
        //Console.WriteLine("Number of elements are {0}",l1.getIterativeCount());
        //Console.WriteLine("Number of elements are {0}",l1.getRecursiveCount(l1.head));
        //l1.deleteLinkedList();
        //Console.WriteLine("Number of elements are {0}",l1.getIterativeCount());
        //if(l1.isPalindromeMain(l1.head))
        //{
        //Console.WriteLine("LL is palindrome");
        //}
        //else
        //{
        //	Console.WriteLine("Not");
        //}
        //l1.printList();
    }
 public void alternateSplit(Node head,Linkedlist a,Linkedlist b)
 {
     Node current=head;
     while(current !=null)
     {
         a.AddFirst(current.data);
         current=current.next;
         if(current!=null)
         {
             b.AddFirst(current.data);
             current=current.next;
         }
     }
 }
    public void alternateSplit(Node head, Linkedlist a, Linkedlist b)
    {
        Node current = head;

        while (current != null)
        {
            a.AddFirst(current.data);
            current = current.next;
            if (current != null)
            {
                b.AddFirst(current.data);
                current = current.next;
            }
        }
    }
 public void mergesort(ref Node n)
 {
     Linkedlist a1=new Linkedlist();
     Linkedlist a2=new Linkedlist();
     if(n==null || n.next==null)
     {
         return;
     }
     //SplitLL(n,a1.head,a2.head);
     SplitLL(n,ref a1.head,ref a2.head);
     //printwithnode(a1.head);
     //printwithnode(a2.head);
     mergesort(ref a1.head);
     mergesort(ref a2.head);
     n=recursiveSortedMerge(a1.head,a2.head);
 }
    static void Main()
    {
        Linkedlist l1 = new Linkedlist();

        l1.AddFirst(5);
        l1.addNodeDown(l1.head, 7);
        l1.addNodeDown(l1.head.down, 8);
        l1.addNodeDown(l1.head.down.down, 30);
        l1.addNodeRight(l1.head, 10);
        l1.addNodeRight(l1.head.right, 19);
        l1.addNodeDown(l1.head.right.right, 22);
        l1.addNodeDown(l1.head.right.right.down, 50);
        l1.addNodeDown(l1.head.right, 20);
        l1.head = l1.flattenFunction(l1.head);
        l1.print();
        //l1.printlist();
    }
    public void mergesort(ref Node n)
    {
        Linkedlist a1 = new Linkedlist();
        Linkedlist a2 = new Linkedlist();

        if (n == null || n.next == null)
        {
            return;
        }
        //SplitLL(n,a1.head,a2.head);
        SplitLL(n, ref a1.head, ref a2.head);
        //printwithnode(a1.head);
        //printwithnode(a2.head);
        mergesort(ref a1.head);
        mergesort(ref a2.head);
        n = recursiveSortedMerge(a1.head, a2.head);
    }
    public void sortedMerge(Node a, Node b)
    {
        Node       current1 = a;
        Node       current2 = b;
        Linkedlist l3       = new Linkedlist();

        if (a == null)
        {
            l3.head = b;
            return;
        }
        if (b == null)
        {
            l3.head = a;
            return;
        }
        while (current1 != null && current2 != null)
        {
            if (current1.data <= current2.data)
            {
                l3.addLastWithTail(current1.data);
                current1 = current1.next;
            }
            else
            {
                l3.addLastWithTail(current2.data);
                current2 = current2.next;
            }
        }
        if (current1 == null)
        {
            l3.tail.next = current2;
        }
        if (current2 == null)
        {
            l3.tail.next = current1;
        }
        l3.printList();
    }
Exemplo n.º 16
0
 public Stack()
 {
     stack = new Linkedlist();
 }
 static void Main()
 {
     Linkedlist l1=new Linkedlist();
     l1.addLastWithTail(1);
     l1.addLastWithTail(5);
     l1.addLastWithTail(7);
     l1.addLastWithTail(9);
     Linkedlist l2=new Linkedlist();
     l2.addLastWithTail(1);
     l2.addLastWithTail(5);
     l2.addLastWithTail(7);
     l2.addLastWithTail(11);
     if(l1.recursiveAreIdentical(l1.head,l2.head))
     {
         Console.WriteLine("Identical");
     }
     else
     {
         Console.WriteLine("not");
     }
     //Linkedlist l3=new Linkedlist();
     //l3.sortedMerge(l1.head,l2.head);
     //l3.head= l3.recursiveSortedMerge(l1.head,l2.head);
     //Linkedlist l3=new Linkedlist();
     //l1.alternateSplit(l1.head,l2,l3);
     //l3.printList();
     //Console.WriteLine("next");
     //l3.printList();
     //l1.AddLast(1);
     //l1.AddLast(2);
     //l1.AddLast(3);
     //l1.AddLast(4);
     //l1.insertAfter(l1.head.next.next,8);
     //l1.insertBefore(l1.head.next,9);
     //l1.printList();
     //Console.WriteLine("Number of elements are {0}",l1.getIterativeCount());
     //Console.WriteLine("Number of elements are {0}",l1.getRecursiveCount(l1.head));
     //l1.deleteLinkedList();
     //Console.WriteLine("Number of elements are {0}",l1.getIterativeCount());
     //if(l1.isPalindromeMain(l1.head))
     //{
         //Console.WriteLine("LL is palindrome");
     //}
     //else
     //{
     //	Console.WriteLine("Not");
     //}
     //l1.printList();
 }
 public void sortedMerge(Node a,Node b)
 {
     Node current1=a;
     Node current2=b;
     Linkedlist l3=new Linkedlist();
     if(a==null)
     {
         l3.head=b;
         return;
     }
     if(b==null)
     {
         l3.head=a;
         return;
     }
     while(current1!=null &&current2!=null)
     {
         if(current1.data<=current2.data)
         {
             l3.addLastWithTail(current1.data);
             current1=current1.next;
         }
         else
         {
             l3.addLastWithTail(current2.data);
             current2=current2.next;
         }
     }
     if(current1==null)
     {
         l3.tail.next=current2;
     }
     if(current2==null)
     {
         l3.tail.next=current1;
     }
     l3.printList();
 }
Exemplo n.º 19
0
 public static void InitList()
 {
     ActionList = new Linkedlist();
     ActionList.AddLast(new DoNothing());
 }
 static void Main()
 {
     Linkedlist l1=new Linkedlist();
     l1.AddFirst(3);
     l1.AddFirst(2);
     l1.AddFirst(6);
     l1.AddFirst(5);
     l1.AddFirst(11);
     l1.AddFirst(10);
     l1.AddFirst(15);
     l1.AddFirst(12);
     //l1.head= l1.reverseAlternateBySize(l1.head,3,true);
     //l1.deleteNodesWithLessValue(l1.head);
     l1.segregateEvenAndOdd(ref l1.head);
     l1.printwithnode(l1.head);
     //l1.printList();
     //l1.printList();
     // int size=l1.getIterativeCount();
     // Linkedlist l2= new Linkedlist();
     // l2.head=l1.IterativeReverse();
     // for(int i=0;i<size;i++)
     // {
     // 	Node head1=l1.head,head2=l2.head;
     // 	if(head1.data!=head2.data)
     // 	{
     // 		Console.WriteLine("Not Palindrome");
     // 		break;
     // 	}
     // 	head1=head1.next;
     // 	head2=head2.next;
     // }
     // l1.printList();
 }
 static void Main()
 {
     Linkedlist l1=new Linkedlist();
     l1.AddFirst(5);
     l1.addNodeDown(l1.head,7);
     l1.addNodeDown(l1.head.down,8);
     l1.addNodeDown(l1.head.down.down,30);
     l1.addNodeRight(l1.head,10);
     l1.addNodeRight(l1.head.right,19);
     l1.addNodeDown(l1.head.right.right,22);
     l1.addNodeDown(l1.head.right.right.down,50);
     l1.addNodeDown(l1.head.right,20);
     l1.head= l1.flattenFunction(l1.head);
     l1.print();
     //l1.printlist();
 }
 static void Main()
 {
     Linkedlist l1=new Linkedlist();
     l1.addLastWithTail(1);
     l1.addLastWithTail(9);
     l1.addLastWithTail(4);
     l1.addLastWithTail(2);
     //l1.addLastWithTail(3);
     //l1.addLastWithTail(5);
     l1.mergesort(ref l1.head);
     l1.printwithnode(l1.head);
 }
Exemplo n.º 23
0
 public Interface_Stack()
 {
     gameObjectStack = new Linkedlist <GameObject>();
 }