changeset 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 7e3fab27a577
children 1d2839ecabda
files bubble_sort/Makefile bubble_sort/bublle_sort.c quick_sort/quick_sort quick_sort/quick_sort.c quick_sort/quick_sort.cbc
diffstat 5 files changed, 92 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bubble_sort/Makefile	Mon Dec 10 17:00:04 2012 +0900
@@ -0,0 +1,16 @@
+CC=cbc-gcc-4.6.0
+CFLAGS= -Wall \
+		-O2 \
+		-g \
+		-o
+
+
+TARGET=bublle_sort
+
+
+$(TARGET): bublle_sort.c
+	cp bublle_sort.c bublle_sort.cbc
+	$(CC) $(CFLAGS) $@ $^
+
+clean:
+	rm -r $(TARGET) *.cbc *.dSYM
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bubble_sort/bublle_sort.c	Mon Dec 10 17:00:04 2012 +0900
@@ -0,0 +1,70 @@
+#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;
+}
+
Binary file quick_sort/quick_sort has changed
--- a/quick_sort/quick_sort.c	Wed Aug 08 18:50:01 2012 +0900
+++ b/quick_sort/quick_sort.c	Mon Dec 10 17:00:04 2012 +0900
@@ -18,16 +18,19 @@
 struct array_state {
     int *int_array_p;
     int *divide_index;
-    int index_num;
     int array_length;
     int upper_count;
     int lower_count;
-    int divide_count;
     int base_value;
     int low_tmp;
     int up_tmp;
 };
 
+struct array_index {
+    int head;
+    int tail;
+}
+
 __code search_lower_array(struct array_state *as_p);
 __code manage_array(struct array_state *as_p);
 
@@ -68,8 +71,7 @@
 __code manage_array(struct array_state *as_p)
 {
     if (as_p->index_num!=0) {
-        as_p->divide_index[as_p->index_num] = as_p->upper_count; 
-        as_p->base_value = as_p->base_value/2;
+
     } 
     goto search_lower_array(as_p);
 }
--- a/quick_sort/quick_sort.cbc	Wed Aug 08 18:50:01 2012 +0900
+++ b/quick_sort/quick_sort.cbc	Mon Dec 10 17:00:04 2012 +0900
@@ -70,7 +70,6 @@
     if (as_p->index_num!=0) {
         as_p->divide_index[as_p->index_num] = as_p->upper_count; 
         as_p->base_value = as_p->base_value/2;
-        
     } 
     goto search_lower_array(as_p);
 }