Mercurial > hg > Members > nobuyasu > CbC
changeset 21:42f3a796c0be draft
add dynamic-fibonacci.cbc
author | Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 07 Aug 2012 19:13:10 +0900 |
parents | 12fe1bbe8b4f |
children | 13a2c13bbd0b |
files | Huffman/test-huffman.c fibonacci/dynamic-fibonacci.cbc |
diffstat | 2 files changed, 66 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/Huffman/test-huffman.c Wed Aug 01 19:36:27 2012 +0900 +++ b/Huffman/test-huffman.c Tue Aug 07 19:13:10 2012 +0900 @@ -65,21 +65,46 @@ quick_sort(numbers, N); +/* int node[2*N]; int node_count = 0; int *prev_node; for (i=0; i<2*N; i++) node[i] = 0; +*/ + + struct node { + int cost; + int *p; + struct node *parent, *l_child, *r_child; + }; + + struct node nodes[N]; + nodes = malloc(sizeof(struct node)*N); + int node_count = 0; + + // initialization of nodes + for (i=0; i<N; i++) { + nodes[i].cost = 0; + nodes[i].parent = NULL; + nodes[i].l_child = NULL; + nodes[i].r_child = NULL; + } + // make tree. for (i=0; i<N; i++ ) { if (*numbers[i] == 0) continue; - node[node_count] = numbers[i]; - - + nodes[node_count] = ; + node_count++; + } + + + free(hoge); + return 0; }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/fibonacci/dynamic-fibonacci.cbc Tue Aug 07 19:13:10 2012 +0900 @@ -0,0 +1,38 @@ +#include <stdio.h> +#include <stdlib.h> + +__code print(int result) +{ + printf("result = %d\n",result); + exit(0); +} + +__code fibonacci1(int result, int num1, int num2, int loop) +{ + + if (loop < 2) goto print(result); + result = num1 + num2; + num1 = num2; + num2 = result; + + loop--; + goto fibonacci1(result, num1, num2, loop); +} + + +__code fibonacci(n) +{ + goto fibonacci1(0, 0, 1, n); +} + +int main(int argc, char* argv[]) +{ + if (argc < 2) { + printf("usage: ./fibonacci number \n"); + exit(0); + } + int n = atoi(argv[1]); + goto fibonacci(n); + + return 0; +}