Example #1
0
 //public ListNode oddEvenList(ListNode head)
 //{
 //    if (head == null) return null;
 //    ListNode node = head;
 //    ListNode newNode = new ListNode();
 //    while (node.next != null)
 //    {
 //        if (node.val % 2 != 0)
 //        {
 //            newNode.AddToTail(node.val);
 //        }
 //        node = node.next;
 //        if (node.next == null)
 //        {
 //            newNode.AddToTail(node.val);
 //        }
 //    }
 //    while (head.next != null)
 //    {
 //        if (head.val % 2 == 0)
 //        {
 //            newNode.AddToTail(head.val);
 //        }
 //        head = head.next;
 //        if (head.next == null)
 //        {
 //            newNode.AddToTail(head.val);
 //        }
 //    }
 //    return newNode;
 //}
 public void AddToTail(int val)
 {
     ListNode newNode = new ListNode(val);
     ListNode current = this;
     while (current.next != null)
     {
         current = current.next;
     }
     current.next = newNode;
 }
Example #2
0
        public ListNode OddEvenList(ListNode head)
        {
            ListNode oddposition = new ListNode(1);
            ListNode evenposition = new ListNode(2);
            ListNode oddStart;
            ListNode evenStart;
            bool isodd = false;

            if (head == null || head.next == null) return head;

            oddposition = head;
            oddStart = head;

            head = head.next;
            evenposition = head;
            evenStart = head;

            while (head.next != null)
            {
                head = head.next;
                isodd = !isodd;

                if (isodd)
                {
                    oddposition.next = head;
                    oddposition = head;
                }
                else
                {
                    evenposition.next = head;
                    evenposition = head;
                }

            }
            oddposition.next = evenStart;
            evenposition.next = null;
            return oddStart;
        }
Example #3
0
        public void run()
        {
            // Print # in  descent triangle
            int num = 6;
            for (int i = 1; i <= num; i++)
            {
                for (int j = 1; j <= num; j++)

                {
                    if ((i + j) > num)
                    {

                        Console.Write("#");
                    }
                    else
                    {
                        Console.Write(" ");
                    }

                }
                Console.WriteLine();

            }

            //Setup 11
            CsharpStringExs instance = new CsharpStringExs();

            //Ex.1  Reverse a word Charactrers
            string strTest = "Rahmo";
            string result = instance.ReverseString(strTest);
            Console.WriteLine(result);

            //Ex.2 Reverse the words in a sentence
            String strTest2 = "Hello, It's me ;)";
            string result2 = instance.ReverseSentence(strTest2);
            Console.WriteLine(result2);

            //Ex.3 check if string is palindrome
            string pan1 = "cocoococ";
            string pan2 = "qqaabb";
            Console.WriteLine(pan1 + " palindrome check is " + instance.isPalindrome(pan1) + " \n" + pan2 +
                              " palindrome check is " + instance.isPalindrome(pan2));

            //Ex.4 Check if String contains Only Capital Charactars
            string strcap1 = "Reeefe";
            string strcap2 = "SWEET";
            Console.WriteLine(strcap1 + " capital check is " + instance.isCapitalOnly(strcap1) + " \n" + strcap2 +
                              " capital check is " + instance.isCapitalOnly(strcap2));

            int[] reArrange = new[] {1, 2, 3, 4, 5, 6, 7};
            string reArrangeStr = String.Join(",", reArrange).ToString();
            string result1 = String.Join(",", instance.arrangeMaxMInts(reArrange)).ToString();

            Console.WriteLine("Rearrange an array in maximum minimum of " + reArrangeStr + " is: " + result1);
            //Ex.5 Arrang array Input  :
            // arr[] = {1, 2, 3, 4, 5, 6, 7}
            // Output: arr[] = { 7, 1, 6, 2, 5, 3, 4 }

            Console.WriteLine(Solution.result);

            int[] arr = {1,2,3,3,2,1,3};
            Console.WriteLine(" the Number Occurring Odd Number of Times " + instance.findNumberOccuringOdd(arr));

             string Rahm = "Rahmo";
            //string Rahm = "Rssmoo";
            Console.WriteLine(" isUnique check  " + instance.isUniqueChar(Rahm));

            string perm1 = "sumit";
            string perm2 = "tiums";
            Console.WriteLine(" Permutation check  " + instance.CheckPermutation(perm1, perm2));

            string UrlFyMe = "12   f";
            Console.WriteLine(" Permutation check  " + instance.urlfy(UrlFyMe,5));

            // Example Check if the first letter is capital in a typcal word
            string Testword = "rahmo";
            Console.WriteLine(CheckCab(Testword).ToString() + " Check cab resultss");

            LinkedList<int> list = new LinkedList<int>();
            list.AddLast(1);
            list.AddLast(2);
            list.AddLast(3);
            list.AddLast(4);
            list.AddLast(5);

            int n = Console.Read();
            Console.WriteLine(n);
            for (int i = 0 ; i <= n; i++ )
            {
                int FirstSide = Console.Read();
                int SecondSide = Console.Read();
                int ThirdSide = Console.Read();
                if (FirstSide == SecondSide && FirstSide == ThirdSide)
                {
                    Console.WriteLine("Equilateral");
                }
                else if (FirstSide == SecondSide || FirstSide == ThirdSide)
                {
                    Console.WriteLine("Isosceles");
                }
                else
                {
                    Console.WriteLine("None of these");
                }
            }

            Console.WriteLine(" the list conents  " + list.Last.Value.ToString());
            //135789
            ListNode listNode = new ListNode(1);
            listNode.AddToTail(2);
            listNode.AddToTail(3);
            listNode.AddToTail(4);
            listNode.AddToTail(5);
            listNode.AddToTail(6);

            ListNode listNode2 = new ListNode(1);
            listNode2.AddToTail(2);
            listNode2.AddToTail(3);

            ListNode OddevenNode = listNode.reversell(listNode);
             OddevenNode = listNode.OddEvenList(listNode);

            while (OddevenNode.next != null)
            {

                Console.WriteLine(OddevenNode.val.ToString());
                if (OddevenNode.next != null)
                {
                    OddevenNode = OddevenNode.next;
                }

            }

            Console.ReadLine();
        }
Example #4
0
 public ListNode OddEvenList(ListNode head)
 {
     return head;
 }
Example #5
0
 public ListNode reversell(ListNode head)
 {
     ListNode reversedPart = null;
     ListNode current = head;
     while (current != null)
     {
         ListNode next = current.next;
         current.next = reversedPart;
         reversedPart = current;
         current = next;
     }
     head = reversedPart;
     return head;
 }
Example #6
0
 public ListNode oddEvenList(ListNode head)
 {
     if (head == null) return head;
     ListNode p = head, q = head;
     while (q != null)
     {
         q = q.next;
         if (q == null || q.next == null) break;
         ListNode next_p = p.next, next_q = q.next;
         q.next = next_q.next;
         p.next = next_q;
         next_q.next = next_p;
         p = p.next;
     }
     return head;
 }