generated from Aarhus-University-ECE/285191U013-IPFCE-assignment-1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinked_list.c
More file actions
39 lines (30 loc) · 741 Bytes
/
linked_list.c
File metadata and controls
39 lines (30 loc) · 741 Bytes
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
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include "linked_list.h"
node *make_node(const int v, node *q) {
node *p = (node*) malloc(sizeof(node));
if (p == NULL) {
fprintf(stderr, "%s:%d Failed to allocate memory\n", __FILE__, __LINE__);
exit(1);
}
p->data = v;
p->next = q;
return p;
}
// exercise 1
void print_list(node *p) {
}
// exercise 2
int sum_squares(node *p) {
return -1;
}
// exercise 3
node *map(node *p, int(*f)(int)) {
return NULL;
}
int square(const int x) { return x * x; }
// example of another function that can be passed to map
// returns the sign of the number
// -1 if negative, 0 if zero, 1 if positive
int sign(const int x) { return x == 0 ? 0 : (x < 0 ? -1 : 1); }