Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "queue.h"
- Queue_ptr createQueue() {
- Queue_ptr s = (Queue_ptr)malloc(sizeof(Queue));
- s->front = NULL;
- s->back = NULL;
- return s;
- }
- void enqueue(Queue_ptr s, element e) {
- DN_ptr n = (DN_ptr)malloc(sizeof(DLLNode));
- n->e = e;
- if (s->front == NULL) {
- n->next = NULL;
- s->front = n;
- s->back = n;
- }else{
- s->back->next = n;
- n->prev = s->back;
- s->back = n;
- }
- }
- element dequeue(Queue_ptr s) {
- DN_ptr temp = s->front->next;
- element e = s->front->e;
- free(s->front);
- s->front = temp;
- s->front->next = NULL;
- s->front->prev = NULL;
- return e;
- }
- int isEmpty(Queue_ptr s) {
- if (s->front == NULL)
- return 1;
- else
- return 0;
- }
- element peek(Queue_ptr s) {
- return s->front->e;
- }
- void display(Queue_ptr s) {
- DN_ptr temp = s->back;
- while (temp) {
- printf("%dn", temp->e);
- temp = temp->prev;
- }
- }
- void destroyQueue(Queue_ptr s) {
- DN_ptr temp = s->front;
- DN_ptr next;
- while (temp) {
- next = temp->next;
- free(temp);
- temp = next;
- }
- free(s);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement