#include #include #define _OUTPUT int main(int argc, char* argv[]) { int count = 1000; int *list; int swaps = 0; int runs = 0; int biggest = 0; int smallest = 0; printf("Random list sorting\nLenght of List:%i \n\n", count); list = malloc(sizeof(int) * count); srandom(list); for(int i = 0; i < count; i++) { list[i] = random()/361913; #ifdef _OUTPUT printf("%i,", list[i]); #endif } printf("\n==========Sorting==========\n"); do { swaps = 0; runs++; for( int i = 1; i < count; i++ ) { if(list[i - 1] > list [i]) { int tmp = list[i - 1]; list[i - 1] = list[i]; list[i] = tmp; swaps++; } } } while(swaps); #ifdef _OUTPUT for(int i = 0; i < count; i++) { printf("%i,",list[i]); } #endif printf("\n\nNeeded runs: %i\n", runs); free(list); return 0; }