Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/ipc.h>
- #include <sys/msg.h>
- #define MSGSIZE 100
- #define MSGTYPE1 1
- #define MSG_REGQ 2
- #define MSGTYPE3 3
- #define MSG_LEAVEQ 4
- #define ERRCODE -1
- #define ALLTYPES 0
- struct Node {
- pid_t member;
- struct Node* next;
- };
- typedef struct Node Node;
- typedef struct mmbrlist{
- Node* head;
- Node* tail;
- } mmbrlist;
- struct message {
- long mtype;
- pid_t pid;
- char mtext[MSGSIZE];
- };
- typedef struct message message;
- mmbrlist initmmbrList() {
- Node* head = (Node*)malloc(sizeof(Node));
- head->member = 0;
- head->next = NULL;
- mmbrlist list = {head, head};
- return list;
- }
- int ml_pushback(mmbrlist* list, pid_t item){
- Node* toadd = (Node*)malloc(sizeof(Node));
- if (NULL == toadd) {
- return EXIT_FAILURE;
- }
- toadd->next = NULL;
- toadd->member = item;
- list->tail->next = toadd;
- list->tail = toadd;
- return EXIT_SUCCESS;
- }
- void ml_removenode(Node* prev){
- Node* todel = prev->next;
- prev->next = todel->next;
- free(todel);
- }
- void ml_remove(mmbrlist* list, pid_t item){
- for (Node* curNode = list->head;
- curNode != NULL;
- curNode = curNode->next)
- {
- if (curNode->next == NULL)
- break;
- if (curNode->next->member == item)
- ml_removenode(curNode);
- }
- }
- void ml_clear(Node* head){
- if (NULL == head)
- return;
- ml_clear(head->next);
- free(head);
- }
- int ml_isempty(mmbrlist list) {
- return list.head->next == NULL;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement