void pArr(int v[],int left,int right)
{
int i;
for(i=left;i<=right;i++) printf("%d ",v[i]); printf("\n"); } void swap(int v[],int i,int j) { int tmp; tmp= v[i]; v[i] = v[j]; v[j] = tmp; } void qsort(int v[],int left,int right) { int i,last; pArr(v,left,right); if (left >= right)
return;
swap(v,left,(left+right)/2);
last = left;
for(i = left + 1;i<=right; i++)
if(v[i] < v[left])
swap(v,++last,i);
swap(v,left,last);
qsort(v,left,last - 1);
qsort(v,last + 1,right);
}
int main()
{
int a[8] = {1,5,8,11,3,4,2,3};
pArr(a,0,7);
qsort(a,0,7);
pArr(a,0,7);
}
Subscribe to:
Post Comments (Atom)
Blog Archive
-
▼
2009
(46)
-
▼
December
(16)
- Insert Ignore and Replace in MySql
- mysql command prompt paging options
- mysql command prompt auto completion
- Oracle trigger question
- Finding whether a number is blessed or not
- Generating readable assembly with gcc
- Brace matching : Flex Builder
- Finding which place belongs to which district usin...
- Iterative/Non-recursive version of pre order/in or...
- C Dictionary
- A whiteboard built using Flex/PHP/MySql
- Maximum contiguous subarray problem
- Passing array parameters in Java and C
- Grep for space and new line
- Quick Sort in C by Kernighan Ritchie
- A simple hash implementation in C
-
▼
December
(16)
No comments:
Post a Comment