RSS Forums RSS
Please support our C# advertiser: Programming Forums

Array Index Problem in Quick Sort

Join Date: Mar 2007
Posts: 25
Reputation: shsh_shah is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
shsh_shah shsh_shah is offline Offline
Light Poster

Re: Array Index Problem in Quick Sort

  #3  
Mar 27th, 2007
Originally Posted by jslicer View Post
Remove "hi = arr.Length;" and pass in arr.Length-1 as the hi parameter on your first call to the function.


Hi Thanks for help i have changed small bit code

public static void quicks(int [] arr,int lo, int hi)
        {
            int i = lo;
            int temp;
            int j = hi;
            int pivot;
            pivot = arr[(lo + hi) / 2];

            if (i >= j)
            {
                return;
            }

                while (i < j)
                {
                    while (i<j && arr[i] < pivot)
                    {
                        i++;
                    }
                    while (i<j && arr[j] >= pivot)
                    {
                        j--;
                    }
                    
                    if (i < j)
                    {
                    temp = a[i];
                    a[i] = a[j];
                    a[j] = temp;
                    }
                
                }  // end of do condition

            if (j < i)
            {
                temp = j;
                j = i;
                i = temp;
            }
          
 // i took these two below recursive functions from web and i am also getting problem now in below functions Error="System.StackOverFlowException"
// Can you help me in this and also if tell me what they do
          if (lo<j)  quicks(arr,lo, j);
          if(i<hi)   quicks(arr,j,hi);


        } // end of QuickS

        public static void quicks(int[] arr)
        {
            quicks(arr, 0, arr.Length - 1);
        }


Thanks for quick response. Plz help small bit more.
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 9:12 am.
Newsletter Archive - Sitemap - Privacy Statement - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC