-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathll.c
39 lines (34 loc) · 790 Bytes
/
ll.c
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 <stdio.h>
#include <stdlib.h>
#include "ll.h"
node *createnode(double x, double y){
node *newNode = malloc(sizeof(node));
newNode->x = x;
newNode->y = y;
newNode->next = NULL;
return newNode;
}
list *ll_new(){
list *list = malloc(sizeof(list));
list->head = list->tail = NULL;
list->ct = 0;
return list;
}
void ll_add(double x, double y, list *list){
if(list->head == NULL){
list->head = list->tail = createnode(x, y);
} else {
list->tail = list->tail->next = createnode(x, y);
}
list->ct++;
}
void ll_free(list * list){
node *current = list->head;
node *next = current;
while(current != NULL){
next = current->next;
free(current);
current = next;
}
free(list);
}