3047: Quick Sort algorithm time limit:1 Sec Memory limit:128 MB
submit:287 solved:252
[Submit] [Status] [Web Board] Description
Design a program that implements a quick sort algorithm and outputs the sorting process for {6,8,7,9,0,1,3,2,4,5}.
Input Output
Each sorting process outputs a row until the sort is complete.
Sample Output
6,8,7,9,0,1,3,2,4,5 ...
HINT
#include <stdio.h>void quicksort (int a[],int left,int right) { int i,j,temp,t,k; if (left>right) return; Temp=a[left]; I=left; J=right; while (i!=j) { while (a[j]>=temp&&i<j) j--; while (a[i]<=temp&&i<j) i++; if (i<j) { t=a[i]; A[I]=A[J]; a[j]=t; } } A[left]=a[i]; A[i]=temp; for (k=0;k<10;k++) { if (k==9) printf ("%d", a[k]); else printf ("%d,", a[k]); } printf ("\ n"); Quicksort (a,left,i-1); Quicksort (a,i+1,right); return;} int main () { int a[10]={6,8,7,9,0,1,3,2,4,5}; Quicksort (a,0,9); return 0;}
Or a quick sort, just print out every step.
3047: Fast Sorting algorithm