QuickSort Array Out of Bound problem

shah123's Avatar
Now i have another problem when i get an array using

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)
                    while (arr[i] < pivot)
                    while (arr[j] > pivot) // when it comes here it says Array
                                          //  out of bound problem   

                    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
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
What is the initial value of of hi and lo that is passed to the function.

The exception you are talking about looks like hi is not within the range of arr.
shah123's Avatar
I have sorted this problem thanks a million for all help.