-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist.c
More file actions
75 lines (64 loc) · 1.25 KB
/
Copy pathlist.c
File metadata and controls
75 lines (64 loc) · 1.25 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "list.h"
#include "drawer.h"
#include "list.h"
#include "rules.h"
#include <stdlib.h>
#include <stdio.h>
struct node{
char value;
Node next;
};
struct list{
Node head;
int length;
};
List newList(){
List l= malloc(sizeof(struct list));
l->head=NULL;
l->length=0;
return l;
}
void print(List l, Drawer d, char ch){
char c=ch;
Drawer f=clone(d);
Node n = malloc(sizeof(struct node));
for(n=l->head; n!= NULL; n=n->next){
movequeue(f, n->value, c);
f=clone(f);
}
}
void addHead(List l, char c){
Node n = malloc(sizeof(struct node));
n->value=c;
n->next = l->head;
l->head = n;
l->length++;
}
void removeHead(List l){
Node n = malloc(sizeof(struct node));
n=l->head;
n=n->next;
free(l->head);
l->head=n;
l->length--;
}
void removeLast(List l){
if(l->length==1)
removeHead(l);
else{
Node n = malloc(sizeof(struct node));
Node prev = malloc(sizeof(struct node));
for(n=l->head; n->next!=NULL ;prev=n, n=n->next);
free(n);
prev->next=NULL;
l->length--;
}
}
int length(List l){
return l->length;
}
int isempty(List l){
if(l->head == NULL)
return 1;
return 0;
}