Posts

Showing posts from November, 2020

DEQUE implementation Using Arrays

 Deque is a double Ended queue, where you can insert and delete from both front and rear end. Deque is of two types:  1) INPUT restricted Deque - in it you can enter the element from only one end either from front or rear. But can delete from both ends. 2) OUTPUT restricted Deque - In it you can delete elements from only one end either from front or rear. But can insert from both ends. A Deque follows properties of both stack and queue. It follows STACK (LIFO) in such a way that we can restrict insertion and deletion from only one end, like Stack. It follows QUEUE (FIFO) Property in such a way that we can restrict insertion from rear end and deletion from front end, and we can set any end as rear or front because elements can be deleted or inserted from both the end. CODE: #include<conio.h> #include<stdlib.h> #include<stdio.h> void enqueue_front(int d[], int *f, int *r, int size) {     int data;     if((*f==0 && *r==size-1) ||(*...

Simple Queue (Non-circular) implementation using stack through arrays in c

Queue can be implemented by using two stacks, either making (enqueue operation expensive O(n) and dequeue  operation simple O(1)) or (enqueue operation simple O(1) and dequeue operation expensive O(n)). I've done it by Enqueue operation simple O(1)  and Dequeue operation expensive O(n). Note: A stack can also be implemented using Queue by?? #include<conio.h> #include<stdlib.h> #include<stdio.h> void enqueue(int stack[], int *top, int size, int data) {     *top=*top+1;     stack[*top]=data; } void dequeue(int s1[], int *t1, int size) {     int i,top;     int stack2[size], top2=-1; if(*t1==-1)     printf("Queue is already empty!"); else     {        for(i=*t1;i>=0;i--)         enqueue(stack2, &top2, size, s1[i]);         //I've pasted the elements of first(actual Queue) stack into second stack, but did not deleted any value from it. Bu...