#include <stdio.h> #include <stdlib.h> template <class Type> void quick_sort(Type a[], int left, int right) { if (left < right) { int p = partion(a, left, right); quick_sort(a, left, p - 1); quick_sort(a, p + 1, right); } } template <class Type> int partion(Type a[], int left, int right) { int i = left; int j = right + 1; Type divide = a[left]; while (true) { while (a[++i] < divide && i < right); while (a[--j] > divide); if (i >= j) { break; } swap(&a[i], &a[j]); } a[left] = a[j]; a[j] = divide; return j; } template <class Type> void swap(Type* a, Type* b) { Type tmp = *a; *a = *b; *b = tmp; } int main(int argc, char** argv) { int* a = (int*) malloc(100 * sizeof(int)); int i = 0; while (scanf("%d", &a[i++]) != EOF && a[i - 1] != 0 && i < 100) { quick_sort(a, 0, i - 1); } int n = 0; for (n = 0; n < i; n++) { printf("%d/t", a[n]); } } #include <stdio.h> #include <stdlib.h> template <class Type> void quick_sort(Type a[], int left, int right) { if (left < right) { int p = partion(a, left, right); quick_sort(a, left, p - 1); quick_sort(a, p + 1, right); } } template <class Type> int partion(Type a[], int left, int right) { int i = left; int j = right + 1; Type divide = a[left]; while (true) { while (a[++i] < divide && i < right); while (a[--j] > divide); if (i >= j) { break; } swap(&a[i], &a[j]); } a[left] = a[j]; a[j] = divide; return j; } template <class Type> void swap(Type* a, Type* b) { Type tmp = *a; *a = *b; *b = tmp; } int main(int argc, char** argv) { int* a = (int*) malloc(100 * sizeof(int)); int i = 0; while (scanf("%d", &a[i++]) != EOF && a[i - 1] != 0 && i < 100) { quick_sort(a, 0, i - 1); } int n = 0; for (n = 0; n < i; n++) { printf("%d/t", a[n]); } }