-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTList.c
executable file
·54 lines (49 loc) · 1.18 KB
/
TList.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
#define _CRT_SECURE_NO_WARNINGS
#include "TList.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "message.h"
void InitList(TList* Head){
Head->head = NULL;
Head->size = 0;
}
void AddInList(TList *Head, int name){
TListElement **temp = &(Head->head);
while (*temp){
temp = &(*temp)->next;
}
*temp = (TListElement *)malloc(sizeof(TListElement));
(*temp)->queue = createQueue();
(*temp)->next = NULL;
(*temp)->idx = name;
Head->size++;
}
TListElement* FindElement(TList * Head, int ind){
TListElement * element = Head->head;
while (element && element->idx != ind){
element = element->next;
}
return element;
}
bool PushMessage(TList* Head, Message_for_server mes){
TListElement *element = FindElement(Head, mes.name);
if (element){
Queue *q = element->queue;
pushQueue(q, mes.string);
return true;
}
else{
return false;
}
}
char *PopMessage(TList *Head, Message_for_server mes){
TListElement *element = FindElement(Head, mes.name);
if (element&&element->queue->size != 0){
strcpy(mes.string, popQueue(element->queue));
return mes.string;
}
else{
return "Massage queue is empty";
}
}