aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErik Liodden <[email protected]>2017-11-30 15:31:06 +0100
committerErik Liodden <[email protected]>2017-11-30 15:31:06 +0100
commit8b6d3de590c9e91299f73660bc0671acfcce1f69 (patch)
tree3ca05b4c8f7f0517baad17743828d5d1cfebe212
parent27d5e32236fdbd4eba7a2a1e344c59b568f2eb98 (diff)
downloadalgdat-8b6d3de590c9e91299f73660bc0671acfcce1f69.tar.gz
oving1 rewritten using the new linked list
rewrote oving1 using the new and imporved linked list.
-rw-r--r--oving1.c34
1 files changed, 14 insertions, 20 deletions
diff --git a/oving1.c b/oving1.c
index e295853..ecc25d9 100644
--- a/oving1.c
+++ b/oving1.c
@@ -15,34 +15,28 @@ int main(void)
{
int num, max;
char buf[BUF_SIZE];
- struct llist *list = llist_init();
+ struct llist l;
+ struct llist_node *node;
+ llist_init(&l, NULL);
/*read from stdin to buffer */
while (fgets(buf, BUF_SIZE, stdin)) {
if (!(isnumber(*buf) || *buf == '-'))
continue;
num = atoi(buf);
- llist_insert_int_beginning(list, num);
+ node = llist_create_node(sizeof(int), NULL);
+ llist_node_set_elem(node, &num);
+ llist_insert_end(&l, node);
}
-
-
- /* traverse the list */
- struct llist_node *x = list->head;
- if (x == NULL) {
- fprintf(stderr, "empty list\n");
- exit(EXIT_SUCCESS);
- }
- max = *(int *)x->data;
- while(x != NULL) {
- if (*(int *)x->data > max)
- max = *(int *)x->data;
- x = x->next;
+ node = l.nil;
+ llist_get_elem(node->next, &max);
+ while ((node = node->next) != l.nil) {
+ llist_get_elem(node, &num);
+ if (num > max)
+ max = num;
}
-
- printf("maximum:\t%d\n", max);
-
+ printf("%d\n", max);
/* free memory allocated by the list */
- llist_free_data_list(list);
-
+ llist_dispose(&l);
return 0;
}