-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathlist.c
40 lines (33 loc) · 795 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
#include <stdio.h>
#include <stdlib.h>
#include "list.h" //interface disertakan
struct Node{
ElementType Element;
Position Next;
};
List Construct(List L){
L = malloc(sizeof(struct Node));
if(L==NULL) printf("Memori Kosong dan Tidak Dapat Dialokasi!!!");
L->Next = NULL;
return L;
}
Position Header(List L){
return L;
}
void Insert(ElementType X, List L, Position P){
Position TmpCell=NULL;
TmpCell = malloc(sizeof(struct Node));
if(TmpCell == NULL) printf("Memori Kosong dan Tidak Dapat Dialokasi!!!");
TmpCell->Element = X;
TmpCell -> Next = P->Next;
//P->Next = TmpCell; //timpa (overwrite) P->Next
}
Position Advance(Position P){
return P->Next;
}
ElementType Retrieve(Position P){
return P->Element;
}
int IsLast(Position P, List L){
return P->Next == NULL;
}