#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <conio.h>
void quick_sort(char* txt, int size)
{
int j = size -1 ;
int k = 0;
int c = txt[(int)(size / 2)];
int tmp = 0;
do
{
while (txt[k] < c)k++;
while (txt[size] < c)size--;
if (k <= size) {
tmp = txt[k];
txt[k] = txt[size];
txt[size] = tmp;
k ++;
size--;
}
}
while (k <= size);
if (size > 0)quick_sort(txt, size);
if (j > 0)quick_sort(txt + k, j - k);
//for (int i = 0; i < size; ++i) {
//printf("%d ", txt[i]);
//}
}
int main()
{
char *txt;
int size = 0;
int t = time(0);
srand(t);
printf("Enter size of mass: ");
if (scanf("%d", &size) != 1)
{
printf("Input Error");
_getch();
return 0;
}
txt = (char*)malloc((size + 1) * sizeof(char));
if (!txt)
{
printf("Can't alloc memory!\n");
return 1;
}
memset(txt, 0, (size + 1) * sizeof(char));
for (int i = 0; i < (size); i++)
{
int r = rand();
char c = (r % 78) + 48;
txt[i] = c;
}
//printf("%d \n", txt);
printf("no sorted: \n");
for (int i = 0; i < size; ++i) {
printf("%d ", txt[i]);
}
quick_sort(txt, size);
printf("\n sorted: \n");
for (int i = 0; i < size; ++i) {
printf("%d ", txt[i]);
}
free(txt);
_getch();
return 0;
}