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

Array Index Problem in Quick Sort

  #1  
Mar 27th, 2007
Hi,
I have problem when i get an array using I get "Array Index Out of Bound" in QuickS function
getArray(int [] arr)
for (i = 0; i < arr.Length; i++)
               {

                   String val = Console.ReadLine();
                   arr[i] = Convert.ToInt32(val);
                }

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

           if (lo >= hi)
           {
               return;
           }
           Console.WriteLine(pivot);

               do
               {
                   while (arr[i] < pivot)
                   i++;
                   while (arr[j] > pivot) // when it comes here it says Array
                                         //  out of bound problem
                   j--;

                   if (i < j)
                   {
                   int temp = a[i];
                   a[i] = a[j];
                   a[j] = temp;
                   }

           } while(i < j ); // end of do condition

           if (lo < j) quicks(lo, j,arr);
           if (i < hi) quicks(i, hi,arr);

Please help me in correcting quicksort function
AddThis Social Bookmark Button
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 5:40 am.
Newsletter Archive - Sitemap - Privacy Statement - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC