using namespace std;
void q_sort(int numbers[], int left, int right);
int cetak(int numbers[], int n){
for(int i=0;i<n;i++)
cout<<numbers[i]<<"\t";
}
int main(){
int i,n;
cout<<"Panjang array: ";
cin>>n;
int numbers[n];
int data[n];
for(int i=0; i<n;i++){
cout<<"Data ke-"<<i<<": ";
cin>>numbers[i];
}
q_sort(numbers,0,n-1);
cetak(numbers,n);
cout<<endl;
system("pause");
}
void q_sort(int numbers[], int left, int right){
int pivot, l_hold, r_hold;
l_hold=left;
r_hold=right;
pivot=numbers[left];
while(left<right){
while((numbers[right]>=pivot)&&(left<right))
right--;
if(left!=right){
numbers[left]=numbers[right];
left++;
}
while((numbers[left]<=pivot)&&(left<right))
left++;
if(left!=right){
numbers[right]=numbers[left];
right--;
}
}
numbers[left]=pivot;
pivot=left;
left=l_hold;
right=r_hold;
if(left<pivot)
q_sort(numbers,left,pivot-1);
if(right>pivot)
q_sort(numbers,pivot+1,right);
}
nb : mau ngopas? silahkan berikan email anda di komentar dan berikan alasan anda atau hubungi email kami :)
Tidak ada komentar:
Posting Komentar