-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathListLinked.c
70 lines (63 loc) · 1.03 KB
/
ListLinked.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
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
#include <stdio.h>
#include <stdlib.h>
#include "ListLinked.h"
void CreateList(List *pl){
pl->head = NULL;
pl->size = 0;
}
int ListEmpty(List *pl){
return !pl->head;
}
int ListFull(List *pl){
return 0;
}
int ListSize(List *pl){
return pl->size;
}
void DestoryList(List *pl){
ListNode *p;
p = pl->head;
while(pl->head){
p = pl->head->next;
free(pl->head);
pl->head = p;
}
pl->size = 0;
}
void insertList(int pos,ListEntry item,List *pl){
ListNode *p = (ListNode *) malloc(sizeof(ListNode));
ListNode *q;
int i;
p->entry = item;
p->next = NULL;
if(pos==0){
p->next = pl->head;
pl->head = p;
}
else{
for(q=pl->head, i = 0;i<pos-1;i++)
q = q->next;
p->next = q->next;
q->next=p;
}
pl->size++;
}
void DeleteList(int pos,ListEntry *item,List *pl){
ListNode *q,*tmp;
int i;
if(pos==0){
*item = pl->head->entry;
tmp = pl-> head->next;
free(pl->head);
pl->head = tmp;
}
else{
for(q=pl->head, i = 0;i<pos-1;i++)
q = q->next;
*item =q->next->entry;
tmp=q->next->next;
free(q->next);
q->next=tmp;
}
pl->size--;
}