-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSlot_LinkedList.c
124 lines (107 loc) · 1.87 KB
/
Slot_LinkedList.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include<stdio.h>
#include<stdlib.h>
#include"STD_TYPES.h"
#include"Slot_LinkedList.h"
Slot * CreateSlotList(Slot * Start)
{
Start = InsertInSlotEmptyList(Start,1);
InsertAtSlotEnd(Start,2);
InsertAtSlotEnd(Start,3);
InsertAtSlotEnd(Start,4);
InsertAtSlotEnd(Start,5);
return Start;
}
Slot * InsertInSlotEmptyList(Slot * Start,s32 Data)
{
Slot * temp = (Slot*)malloc(sizeof(Slot));
temp -> Time = Data;
temp -> prev = NULL;
temp -> next = NULL;
Start = temp;
return Start;
}
void InsertAtSlotEnd(Slot * Start,s32 Data)
{
Slot * temp,*p;
temp = (Slot *)malloc(sizeof(Slot));
temp -> Time = Data;
p = Start;
while(p->next != NULL)
{
p = p->next;
}
p->next = temp;
temp -> next = NULL;
temp -> prev = p;
}
Slot * DeleteSlot(Slot * Start,s32 Data)
{
Slot * temp;
if(Start == NULL)
{
printf("The List is empty\n");
return Start;
}
if(Start->next == NULL)
{
if(Start->Time == Data)
{
temp = Start;
Start = NULL;
free(temp);
}
else
{
printf("The Value %d is not in the List\n",Data);
}
return Start;
}
if(Start->Time == Data)
{
temp = Start;
Start = Start->next;
Start->prev = NULL;
free(temp);
}
temp = Start->next;
while(temp->next!=NULL)
{
if(temp->Time == Data)
{
break;
}
temp = temp->next;
}
if(temp->next != NULL)
{
temp->prev->next = temp->next;
temp->next->prev = temp->prev;
free(temp);
}
else
{
if(temp->Time == Data)
{
temp->prev->next = NULL;
free(temp);
}
else
{
//printf("%d value is not in the List\n",Data);
}
}
return Start;
}
void DisplaySlotList(Slot * Start)
{
Slot * ptr = Start;
if(ptr != NULL)
{
while(ptr != NULL)
{
printf("%d ",ptr -> Time);
printf("\n");
ptr = ptr -> next;
}
}
}