diff --git a/code.cpp b/code.cpp new file mode 100644 index 0000000..805c09b --- /dev/null +++ b/code.cpp @@ -0,0 +1,46 @@ +#include +using namespace std; +void swap(int* num1, int* num2) +{ + int temp = *num1; + *num1 = *num2; + *num2 = temp; +} +int divide(int A[], int low, int high) + { + int pivot = A[high]; + int i = (low - 1); + for (int j = low; j <= high- 1; j++) + { + if (A[j] <= pivot) + { + i++; + swap(&A[i],&A[j]); + } + } + swap(&A[i+1],&A[high]); + return (i + 1); + } + void quickSort(int A[], int low, int high) + { + if (low < high) + { + int p = divide(A,low,high); + quickSort(A, low, p - 1); + quickSort(A, p + 1, high); + } + } +int main() +{ +int n; +cout<<"Enter nubers of element to be sorted"<>n; +int a[n]; +cout<<"Enter the elements"<>a[i]; +quickSort(a,0,n); +cout<<"sorted list"<