public String printForward()
 {
     if (next != null)
     {
         return(data + "->" + next.printForward());
     }
     else
     {
         return(data.ToString());
     }
 }
Esempio n. 2
0
    {//Partition: Write code to partition a linked list around value x, such that all nodes less than x come before all nodes greater than or equal to x.
     //If x is contained within the list, the values of x only need to be after the elements less than x.
        static void Main(string[] args)
        {
            int[]        intArray = new int[] { 3, 5, 8, 5, 10, 2, 1 };
            LinkListNode first    = new LinkListNode(intArray[0]);
            LinkListNode head     = first;

            for (int i = 1; i < intArray.Length; i++)
            {
                LinkListNode second = new LinkListNode(intArray[i]);
                first.next = second;
                first      = second;
            }
            Console.WriteLine(head.printForward());

            LinkListNode newHead = partition2(head, 5);

            Console.WriteLine(newHead.printForward());
        }