#include <iostream> using namespace std; void mquicksort(int A[], int l, int u) { if(l>=u) return; int m=l; for(int i=l+1; i<u; i++) { if(A[i] < A[l]) { int t=A[i]; A[i] = A[m+1]; A[m+1]=t; m++; } } int t=A[l]; A[l] = A[m]; A[m]=t; mquicksort(A, l, m-1); mquicksort(A, m+1, u); } int main() { // your code goes here int A[20]; int n; cout << "enter number of elements(<=20) to be sorted:"; cin >> n; cout << "\nenter " << n << " elements now\n"; for(int i=0;i<n;i++) { cin >> A[i]; } mquicksort(A, 0, n); cout << "\n\nsorted numbers: "; for(int i=0;i<n;i++) { cout << A[i] << " "; } return 0; }
This blog site is dedicated for articles on problem solving using C, C++, data structures, algorithms. Besides this few technical articles are also presented.
Apr 19, 2011
sort an array using quicksort
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment