-
Notifications
You must be signed in to change notification settings - Fork 0
/
List.c
82 lines (65 loc) · 1.26 KB
/
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
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
76
77
78
79
80
81
82
#include <stdio.h>
#include "List.h"
#include <stdlib.h>
//=================Functions=======================
node makeNodo(short a, short b){
node nodo1 = (node) malloc(sizeof(typenode));
nodo1->a = a;
nodo1->b = b;
nodo1->address = NULL;
return nodo1;
}
linkedlist makeList(){
linkedlist listA = (linkedlist) malloc(sizeof(typelist));
listA->head = NULL;
return listA;
}
void push(short a, short b, linkedlist list){
node node1 = makeNodo(a ,b);
node1->address = list->head;
list->head = node1;
}
int pop(linkedlist list)
{
int var[2];
node node1 = list->head;
var[0] = node1->a;
var[1] = node1->b;
list->head = list->head->address;
free(node1);
return var[0];
}
node lastNode(linkedlist list)
{
node p = list->head;
node l;
while(p!=NULL)
{
l = p;
p = p->address;
}
return l;
}
void addElement(short a, short b, linkedlist queue)
{
node node1 = makeNodo(a, b);
if(queue->head==NULL)
{
queue->head = node1;
}
else
{
lastNode(queue)->address = node1;
}
}
short listSize(linkedlist list)
{
node node1 = list->head;
short size = 0;
while(node1!=NULL)
{
size++;
node1 = node1->address;
}
return size;
}