-
Notifications
You must be signed in to change notification settings - Fork 1
/
1.c
123 lines (95 loc) · 2.27 KB
/
1.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
#include<stdio.h>
#include<stdlib.h>
typedef struct node
{
char info;
int priHour;
int priSec;
int priMin;
struct node *next;
}NODE;
typedef struct queue
{
NODE *head;
}QUEUE;
void initList(QUEUE *pq);
void AddEvent(QUEUE *pq,char event, int min,int sec,int hour);
void DeleteEvent(QUEUE *pq,char *event, int *min,int *sec,int *hour);
void initList(QUEUE *pq)
{
pq->head=NULL;
}
void AddEvent(QUEUE *pq, char event, int min,int sec,int hour)
{
NODE *newNode=malloc(sizeof(NODE));
strcpy(newNode->info,event);
newNode->priHour=hour;
newNode->priMin=min;
newNode->priSec=sec;
newNode->next=NULL;
NODE *p=pq->head;
NODE *q=NULL;
while(p!=NULL && p->priHour < newNode->priHour && p->priMin < newNode->priMin && p->priSec < newNode->priSec)
{
q=p;
p=p->next;
}
if(q==NULL)
{
newNode->next=pq->head;
pq->head=newNode;
}
else
{
newNode->next=p;
q->next=newNode;
}
}
void DeleteEvent(QUEUE *pq, char *event, int *min,int *sec,int *hour )
{
NODE *p=pq->head;
*event=p->info;
*hour=p->priHour;
*min=p->priMin;
*sec=p->priSec;
pq->head=pq->head->next;
free(p);
}
void ListEvents(QUEUE *pq) {
NODE *current = pq->head;
if (current == NULL) {
printf("Event list is empty.\n");
return;
}
printf("List of Events:\n");
while (current != NULL) {
printf("Event: %c\n", current->info);
printf("Time: %02d:%02d:%02d\n", current->priHour, current->priMin, current->priSec);
current = current->next;
}
}
void EditEvent(QUEUE *pq, char oldEvent, char newEvent, int newMin, int newSec, int newHour) {
NODE *current = pq->head;
while (current != NULL) {
if (current->info == oldEvent) {
current->info = newEvent;
current->priHour = newHour;
current->priMin = newMin;
current->priSec = newSec;
break;
}
current = current->next;
}
}
//Client code subjected to changes
int main() {
QUEUE eventQueue;
initList(&eventQueue);
AddEvent(&eventQueue, 'A', 10, 15, 9);
AddEvent(&eventQueue, 'B', 30, 45, 11);
AddEvent(&eventQueue, 'C', 20, 0, 10);
ListEvents(&eventQueue);
EditEvent(&eventQueue, 'B', 'X', 35, 50, 11);
ListEvents(&eventQueue);
return 0;
}