-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.c
45 lines (39 loc) · 989 Bytes
/
list.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
40
41
42
43
44
45
#include "list.h"
OpList* OpListInit(){
OpList* self = (OpList*)malloc(sizeof(OpList));
self->head_ = self->tail_ = NULL;
return self;
}
void OpListInsert(OpList* self, Operand val){
OpListNode* p = (OpListNode*)malloc(sizeof(OpListNode));
p->val_ = val;
p->prev = NULL;
if(self->head_ == NULL){
self->head_ = self->tail_ = p;
p->next = NULL;
}
else{
p->next = self->head_;
self->head_->prev = p;
self->head_ = p;
}
}
IntList* IntListInit(){
IntList* self = (IntList*)malloc(sizeof(IntList));
self->head_ = self->tail_ = NULL;
return self;
}
void IntListInsert(IntList* self, int val){
IntListNode* p = (IntListNode*)malloc(sizeof(IntListNode));
p->val_ = val;
p->prev = NULL;
if(self->head_ == NULL){
self->head_ = self->tail_ = p;
p->next = NULL;
}
else{
p->next = self->head_;
self->head_->prev = p;
self->head_ = p;
}
}