Quick Sort
Quick Sort
Expand Post
this code was workin when i used srand function to fill th e array with random numbers and the
array was a declared globally.But now the code is not working.I cant find anything wrong in
this .Sombody pls help..
CPP Syntax (Toggle Plain Text)
1.
2.
3.
4.
5.
6.
7.
8.
#include<iostream.h>
int *a,NUM_ITEMS;
int main()
{
void enterdata();
void quicksort(int,int);
int i;
cout<<"\n\nEnter the number of items:";
cin>>NUM_ITEMS;
a=new int [NUM_ITEMS];
if(a==NULL)
cout<<"Memory allocation error";
cout<<"\nEnter the numbers:";
enterdata();
quicksort(0,NUM_ITEMS-1);
cout<<"Done with sort.\n";
for (i = 0; i <NUM_ITEMS; i++)
cout<<"\n"<<a[i];
return 0;
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
}
void enterdata()
{
int i;
for(i=0;i<NUM_ITEMS;i++)
cin>>a[i];
}
40.
41.
42.
43.
int split(int,int),pivot;
if(upper>lower)
{
pivot=split(lower, upper);
quicksort(lower,pivot-1);
quicksort(pivot+1,upper);
}
44. }
45. int
46.
{
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68. }