Mercurial > hg > GearsTemplate
view src/parallel_execution/examples/sort.cbc @ 358:98c6e13d8ec7
add sort.cbc
author | Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 24 Jun 2017 20:07:27 +0900 |
parents | |
children | ba5959d7901d |
line wrap: on
line source
#include<stdio.h> #include <stdlib.h> #include "../../context.h" #define MAX 20 int main(int argc, char const* argv[]) { struct Context* main_context = NEW(struct Context); initContext(main_context); main_context->next = C_sort_start; goto start_code(main_context); } __code sort_start(struct SortArray* sortArray){ sortArray = new SortArray(); sortArray->array = (Integer**)ALLOC_ARRAY(context, Integer, MAX);//ALLOC_ARRAYはDSの配列なのでintではできない sortArray->loop_counter = 0; goto meta(context, C_make_array); } __code make_array(struct SortArray* sortArray){ if (sortArray->loop_counter == MAX){ sortArray->loop_counter = 0; goto meta(context, C_print); } struct Integer* integer = new Integer(); integer->value = rand() % MAX; sortArray->array[sortArray->loop_counter] = integer; sortArray->loop_counter++; goto meta(context, C_make_array); } __code print(struct SortArray* sortArray){ if (sortArray->loop_counter == MAX){ goto meta(context, C_exit_code); } printf("%d, ", sortArray->array[sortArray->loop_counter]->value); sortArray->loop_counter++; goto meta(context, C_print); }