Skip to content

Commit c6eb699

Browse files
authored
first element as pivot code removed (bug)..
1 parent 3c72ec4 commit c6eb699

File tree

1 file changed

+1
-29
lines changed

1 file changed

+1
-29
lines changed

Quick Sort.c

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,6 @@ void dispArr(int arr_0[], int n)
1313
}
1414

1515

16-
//first element as pivot
17-
int qPartion_f(int arr_0[], int l, int r)
18-
{
19-
int p = arr_0[l];
20-
21-
int i=r, j, temp;
22-
23-
for(j=l+1; j <= r; j++)
24-
{
25-
if(arr_0[j] >= p)
26-
{
27-
temp = arr_0[j];
28-
arr_0[j] = arr_0[i];
29-
arr_0[i] = temp;
30-
i--;
31-
}
32-
}
33-
34-
//now set pivot to it's correct position
35-
temp = arr_0[i];
36-
arr_0[i] = arr_0[l]; // pivot placed on correct position
37-
arr_0[l] = temp;
38-
39-
return i;
40-
}
41-
42-
4316
//last element as pivot
4417
int qPartion_l(int arr_0[], int l, int r)
4518
{
@@ -71,8 +44,7 @@ void quickSort(int arr_0[], int l, int r)
7144
{
7245
if(l < r)
7346
{
74-
int p = qPartion_l(arr_0, l, r); //change this function according to pivot position
75-
47+
int p = qPartion_l(arr_0, l, r);
7648
quickSort(arr_0, l, p-1);
7749
quickSort(arr_0, p+1, r);
7850
}

0 commit comments

Comments
 (0)