aboutsummaryrefslogtreecommitdiffstats
path: root/oving1.c
blob: 55e9ac66c94be347e202e7a342f9aeac9d7006e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
 * oving1.c
 * implements TDT4120 - AlgDat oving 1
 *
 * Erik Liodden
 */

#include <stdio.h>
#include <stdlib.h>
#include "structure.h"
#include "io.h"

int main(void)
{
	int num, max;
	size_t len, i;
	char **lines;
	struct llist l;
	struct llist_node *node;

	llist_init(&l);
	lines = read_lines(&len, stdin);
	for (i = 0; i < len; i++) {
		num = atoi(*(lines + i));
		node = llist_create_node(sizeof(int), NULL);
		llist_node_set_elem(node, &num);
		llist_insert_end(&l, node);
	}

	/* traverse the linked list */
	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("%d\n", max);

	/* free memory allocated by the list */
	dispose_read_lines(lines, len);
	llist_dispose(&l);
	return 0;
}