diff options
author | Kyle K <kylek389@gmail.com> | 2011-07-01 19:43:49 -0500 |
---|---|---|
committer | Kamil Kaminski <kamilkss@gmail.com> | 2011-07-01 19:43:49 -0500 |
commit | 18d02b08d397b1b8f02c94fa11155fb696ec44dc (patch) | |
tree | f5ea69b4be65c4db642b0bdd0b74211509d18412 /linked_list.c | |
parent | 2cf68a5a02f025ce163f99908bd2b768692ad673 (diff) | |
download | sandbox-18d02b08d397b1b8f02c94fa11155fb696ec44dc.tar.gz sandbox-18d02b08d397b1b8f02c94fa11155fb696ec44dc.tar.bz2 sandbox-18d02b08d397b1b8f02c94fa11155fb696ec44dc.zip |
add a pi benchmark and a linked list example
Diffstat (limited to 'linked_list.c')
-rw-r--r-- | linked_list.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/linked_list.c b/linked_list.c new file mode 100644 index 0000000..a9d3089 --- /dev/null +++ b/linked_list.c @@ -0,0 +1,47 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +struct Node +{ + int id; + struct Node *next; +}; +typedef struct Node Node_t; + +Node_t *head = NULL; +Node_t *tail = NULL; + +int main(void) +{ + int i; + for (i = 0; i < 10; i++) + { + if (head == NULL) + { + printf("head, adding id: %d\n", i); + head = (Node_t *) malloc(sizeof(Node_t)); + head->id = i; + head->next = NULL; + tail = head; + } + else + { + printf("tail, adding id: %d\n", i); + Node_t *tmp = (Node_t *) malloc(sizeof(Node_t)); + tmp->id = i; + tmp->next = NULL; + head->next = tmp; + head = head->next; + } + } + + while (tail != NULL) + { + printf("tail: %d\n", tail->id); + tail = tail->next; + } + + return 0; +} + |