Created
October 6, 2017 04:00
-
-
Save ashutoshbsathe/b6b68d6cf8fc20eed16956f0267dc075 to your computer and use it in GitHub Desktop.
Queue using structures and pointers (For Moodle Discussion Forum)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "queue.h" | |
#include <stdlib.h> | |
/* | |
* In queue.h | |
* Queue is defined as | |
* typedef struct queue { | |
* node *head; | |
* node *tail; | |
* node *tmp; | |
* } queue; | |
*/ | |
void qinit(queue *a) { | |
a->head = NULL; | |
a->tail = NULL; | |
a->tmp = NULL; | |
} | |
void enq(queue *a, data b) { | |
/* | |
* Make a->tmp ass your temporary node | |
* Put all your data in it | |
* Link it properly | |
*/ | |
a->tmp = NULL; | |
} | |
int qfull(queue *a) { | |
a->tmp = (node *)malloc(sizeof(node)); /* Reserving memory using tmp */ | |
if(a->tmp == NULL) | |
return 1; | |
else | |
return 0; | |
} | |
int qempty(queue *a) { | |
return a->head == NULL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment