Mercurial > hg > Members > taiki > cbc_test
view bubble_sort/bublle_sort.c @ 7:2698082de0ea
add bubble sort source by cbc.
author | Taiki TAIRA <e095767@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 10 Dec 2012 17:00:04 +0900 |
parents | |
children |
line wrap: on
line source
#include <stdio.h> #include <stdlib.h> __code finish() { printf("finish\n"); } __code print_array(int *array, int count) { if (count < 100) { printf("%d ", array[count]); count++; print_array(array, count); } else { printf("\n"); finish(); } } __code main_loop1(int *array, int count_a, int count_b) { int tmp; if (count_a <= 100) { if (count_b-1 <= 100) { if (array[count_b] > array[count_b+1]) { tmp = array[count_b]; array[count_b] = array[count_b+1]; array[count_b+1] = tmp; } count_b++; goto main_loop1(array, count_a, count_b); } count_a++; count_b = 0; goto main_loop1(array, count_a ,count_b); } int count=0; goto print_array(array, count); } __code make_rand_array(int *array, int array_length, int count) { if (array_length > count) { array[count] = rand()%array_length+1; printf("%d ", array[count]); count++; goto make_rand_array(array, array_length, count); } printf("\n"); int count_a=0; int count_b=0; goto main_loop1(array, count_a, count_b); } void main_loop() { int array_length=100; int *array=(int*)malloc(sizeof(int)*array_length); int count = 0; goto make_rand_array(array, array_length, count); } int main() { main_loop(); return 0; }