public static MyLinkedListNode Reverse(MyLinkedListNode node)
        {
            MyLinkedListNode prev    = null;
            MyLinkedListNode current = node;
            MyLinkedListNode next    = null;

            while (current != null)
            {
                next         = current.next;
                current.next = prev;
                prev         = current;
                current      = next;
            }

            return(prev);
        }
        public static MyLinkedListNode CreateTestLinkList_1()
        {
            //1(random-3)-->2-->3-->4(random-2)-->5
            MyLinkedListNode node1 = new MyLinkedListNode(1);
            MyLinkedListNode node2 = new MyLinkedListNode(2);
            MyLinkedListNode node3 = new MyLinkedListNode(3);
            MyLinkedListNode node4 = new MyLinkedListNode(4);
            MyLinkedListNode node5 = new MyLinkedListNode(5);

            node1.next = node2;
            node2.next = node3;
            node3.next = node4;
            node4.next = node5;
            node5.next = null;

            return(node1);
        }
        public static MyLinkedListNode ImmutableClone(MyLinkedListNode head)
        {
            Dictionary <MyLinkedListNode, MyLinkedListNode> dict = new Dictionary <MyLinkedListNode, MyLinkedListNode>();
            MyLinkedListNode temphead = null;
            MyLinkedListNode newHead  = null;
            MyLinkedListNode origHead = head;

            if (head != null)
            {
                temphead = new MyLinkedListNode(head.data);
                newHead  = temphead;
                dict.Add(head, temphead);
            }

            while (head != null)
            {
                head = head.next;
                MyLinkedListNode prev = temphead;

                temphead = (head == null ? null : new MyLinkedListNode(head.data));
                if (head != null)
                {
                    dict.Add(head, temphead);
                }

                prev.next = temphead;
            }

            head     = origHead;
            temphead = newHead;
            while (head != null)
            {
                if (head.random != null)
                {
                    temphead.random = dict[head.random];
                }

                head     = head.next;
                temphead = temphead.next;
            }

            return(newHead);
        }
        static void Main(string[] args)
        {
            //MyLinkedListNode head = MyLinkedListNode.CreateTestLinkList_1();
            //MyLinkedListNode.PrintLinkedList(head);
            //MyLinkedListNode.PrintLinkedList(MyLinkedListNode.RotateLinkListAtKthNode(head, 4));


            //int[] arr = {1,2 , 7,9,100};
            //Console.WriteLine(Search.FindValOrNextSmallest(arr,99));

            //TreeNode<int> node = TreeNode<int>.GetSampleTree();

            //node.PrintInorderRecursively(node);
            //Console.WriteLine();


            //node.PrintLevelorderIteratively(node);
            //node.PrintLevelorderRecursively(node);
            //Console.WriteLine(TreeNode<int>.HeightOfTreeNode(node.right));
            //Console.WriteLine(BitTest.itoa(4));
            //TestMain();
            //TestTreeConstruction();

            //int[] arr = {2, 2,2, 7, 8, 9 };
            //int[] arr = { 1,2, 3,4};
            //Console.WriteLine(Search.RotateArrayPivot(arr, 0, arr.Length-1));
            //Console.WriteLine(RecursionPractice.changePi("xpix"));
            //Console.WriteLine(RecursionPractice.changePi("pipi"));
            //Console.WriteLine(RecursionPractice.changePi("pip"));
            //Console.WriteLine(RecursionPractice.pairStar("hello"));
            //PrintArrayOfArray(Triangle.PrintPascalTriangle(4));
            //PrintArray(StringTest.Permutations("ABC"));
            //StringTest.PermutationsWithRepetetion("AABC");
            //TestTree();
            //Graph2.TestGraph();
            //HeapTest();
            //ClosestPairCalc.InternalMain();
            //Console.WriteLine(RecursionPractice.countHi("xhixhxihihhhih"));

            MyLinkedListNode.InternalMain();
            Console.Read();
        }
        public static MyLinkedListNode RotateLinkListAtKthNode(MyLinkedListNode head, int k)
        {
            if ((head == null) || (k < 0))
            {
                return(null);
            }
            MyLinkedListNode origHead = head;
            MyLinkedListNode last     = head;
            MyLinkedListNode prev     = null;
            MyLinkedListNode begin    = last;
            bool             setHead  = false;

            while (last != null)
            {
                int i = 0;
                while (i < k - 1 && last != null && last.next != null)
                {
                    i++;
                    prev = last;
                    last = last.next;
                }

                prev.next = last.next;
                if (begin != last)
                {
                    last.next = begin;
                }
                if (!setHead)
                {
                    origHead = last;
                    setHead  = true;
                }
                last  = prev.next;
                prev  = last;
                begin = last;
            }

            return(origHead);
        }
 public MyLinkedListNode(int pData, MyLinkedListNode pNext, MyLinkedListNode pRand)
 {
     this.data   = pData;
     this.next   = pNext;
     this.random = pRand;
 }
 public MyLinkedListNode(int pData, MyLinkedListNode pNext)
 {
     this.data = pData;
     this.next = pNext;
 }