From 18d02b08d397b1b8f02c94fa11155fb696ec44dc Mon Sep 17 00:00:00 2001 From: Kyle K Date: Fri, 1 Jul 2011 19:43:49 -0500 Subject: add a pi benchmark and a linked list example --- linked_list.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 linked_list.c (limited to 'linked_list.c') 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 +#include +#include + +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; +} + -- cgit v1.2.3