forked from akij17/Data-Structures-in-Pure-C
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueue_ll.c
43 lines (36 loc) · 848 Bytes
/
queue_ll.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
//
// Created by Parth Soni on 11/15/2018.
//
#include "queue_ll.h"
#include "linkedlist.h"
#include <stdio.h>
#include <malloc.h>
queue_ll *new_queue_ll(){
linkedList *ll = newLinkedList();
queue_ll *q = malloc(sizeof(queue_ll)+ sizeof(ll));
q->size = 0;
q->data = ll;
return q;
}
void enqueue_queue_ll(queue_ll *q, int item){
insert_linkedList((q->data), item, 999);
q->size++;
}
int dequeue_queue_ll(queue_ll *q){
if(q->size>0){
int item = q->data->head->next->data;
q->data->head->next = q->data->head->next->next;
q->size--;
return item;
}
else
return -1;
}
int front_queue_ll(queue_ll *q){
if(q->size>0){
int item = q->data->head->next->data;
return item;
}
else
return -1;
}