if the queue contains one element then front end is equal to the rear end.
A queue is simply a FIFO i.e first in first out. In queue we've front and rear. Front is the initial or first location of the queue whereas rear indicates the last entry location in the queue. In the circular queue the location of front and rear will be the same IF the total space of the circular queue is utilized. Each element has its position no. for insertion , if we set the 5th element as the front element then after every insertion the ptr indicates the 5th element as front. in deletion, the fifth element is deleted every time it is the rear position. after deletion of an element the queue rotates and every time the rear indicates the 5th element of the circular queue. and every time the 5th location element is deleted.
In queue insertion takes place on rear end and deletion takes place on front end. INSERTION(QUEUE,N,FRONT,REAR,ITEM) :QUEUE is the name of a array on which we are implementing the queue having size N. view comlete ans at http://mcabcanotes.in/algorithm-to-perform-insertion-and-deletion-in-a-queue/
linear quene said to empty when front==rear==-1 or front==rear
The Method To Add an element in Circular Queue # define MAXQUEUE 100 struct queue{ int items[MAXQUEUE]; int front, rear; } struct queue q; q.front=q.rear=MAXQUEUE -1; void ENQ(struct queue *pq, int x) { /* make room for new element*/ if(pq ->rear = MAXQUEUE - 1) pq-> rear = 0; else (pq->rear)++; /* check for overflow */ if(pq ->rear==pq->front) { printf("queue overflow); exit(1); } pq->items[pq->rear]=x; return; }/* end of ENQ*/ A Method to Delete an element from Circular Queue int DQ(struct queue *pq) { if(pq-> rear == pq-> front) { printf("queue underflow"); exit(1); }/*end if*/ if(pq->front = = MAXQUEUE-1) pq->front=0; else (pq->front)++; return(pq->items[pq->front]);
There are 2 conditions for queue full if queue is implemented using arrays. First condition is Front = 1 and Rear = N Second condition is Front = Rear + 1
Delete Front---- DQDELETE_FRONT(QUEUE, FRONT, REAR, ITEM) 1. [check for queue underflow] If FRONT<0, Then: Print: "Queue is empty", and Return. 2. ITEM = QUEUE[FRONT]; 3. Set FRONT = FRONT + 1. 4. Return. Delete Rear---- DQDELETE_REAR(QUEUE, REAR, FRONT, ITEM) 1. [check for queue underflow] If REAR<0, Then: Print: "Queue is empty", and Return. 2. ITEM = QUEUE[REAR]. 3. Set REAR = REAR - 1. 4.Return.
A circular queue is similar to the normal queue with the difference that queue is circular queue ; that is pointer rear can point to beginning of the queue when it reaches at the end of the queue. Advantage of this type of queue is that empty location let due to deletion of elements using front pointer can again be filled using rear pointer. There are 2 conditions for queue full if queue is implemented using arrays. First condition is Front = 1 and Rear = N Second condition is Front = Rear + 1
A queue is simply a FIFO i.e first in first out. In queue we've front and rear. Front is the initial or first location of the queue whereas rear indicates the last entry location in the queue. In the circular queue the location of front and rear will be the same IF the total space of the circular queue is utilized. Each element has its position no. for insertion , if we set the 5th element as the front element then after every insertion the ptr indicates the 5th element as front. in deletion, the fifth element is deleted every time it is the rear position. after deletion of an element the queue rotates and every time the rear indicates the 5th element of the circular queue. and every time the 5th location element is deleted.
A queue is simply a FIFO i.e first in first out. In queue we've front and rear. Front is the initial or first location of the queue whereas rear indicates the last entry location in the queue. In the circular queue the location of front and rear will be the same IF the total space of the circular queue is utilized. Each element has its position no. for insertion , if we set the 5th element as the front element then after every insertion the ptr indicates the 5th element as front. in deletion, the fifth element is deleted every time it is the rear position. after deletion of an element the queue rotates and every time the rear indicates the 5th element of the circular queue. and every time the 5th location element is deleted.
In queue insertion takes place on rear end and deletion takes place on front end. INSERTION(QUEUE,N,FRONT,REAR,ITEM) :QUEUE is the name of a array on which we are implementing the queue having size N. view comlete ans at http://mcabcanotes.in/algorithm-to-perform-insertion-and-deletion-in-a-queue/
linear quene said to empty when front==rear==-1 or front==rear
The queue is a linear data structure where operations od insertion and deletion are performed at separate ends also known as front and rear. Queue is a FIFO structure that is first in first out. Whenever a new item is added to queue, rear pointer is used. and the front pointer is used when an item is deleted from the queue.
The Method To Add an element in Circular Queue # define MAXQUEUE 100 struct queue{ int items[MAXQUEUE]; int front, rear; } struct queue q; q.front=q.rear=MAXQUEUE -1; void ENQ(struct queue *pq, int x) { /* make room for new element*/ if(pq ->rear = MAXQUEUE - 1) pq-> rear = 0; else (pq->rear)++; /* check for overflow */ if(pq ->rear==pq->front) { printf("queue overflow); exit(1); } pq->items[pq->rear]=x; return; }/* end of ENQ*/ A Method to Delete an element from Circular Queue int DQ(struct queue *pq) { if(pq-> rear == pq-> front) { printf("queue underflow"); exit(1); }/*end if*/ if(pq->front = = MAXQUEUE-1) pq->front=0; else (pq->front)++; return(pq->items[pq->front]);
The queue is a linear data structure where operations of insertion and deletion are performed at separate ends also known as front and rear. Queue is a FIFO structure that is first in first out. A circular queue is similar to the normal queue with the difference that queue is circular queue ; that is pointer rear can point to beginning of the queue when it reaches at the end of the queue. Advantage of this type of queue is that empty location let due to deletion of elements using front pointer can again be filled using rear pointer. A double ended queue (or deque ) is a queue where insertion and deletion can be performed at both end that is front pointer can be used for insertion (apart from its usual operation i.e. deletion) and rear pointer can be used for deletion (apart from its usual operation i.e. insertion)
There are 2 conditions for queue full if queue is implemented using arrays. First condition is Front = 1 and Rear = N Second condition is Front = Rear + 1
The queue is a linear data structure where operations of insertion and deletion are performed at separate ends also known as front and rear. Queue is a FIFO structure that is first in first out. A circular queue is similar to the normal queue with the difference that queue is circular queue ; that is pointer rear can point to beginning of the queue when it reaches at the end of the queue. Advantage of this type of queue is that empty location let due to deletion of elements using front pointer can again be filled using rear pointer.
#include<stdio.h> #include<conio.h> int q[5],front=-1,rear=-1,max=5; void print() { int i; if(front==-1) printf("QUEUE EMPTY"); else { if(front<=rear) for(i=front;i<=rear;i++) printf(" %d ",q[i]); else { for(i=0;i<=rear;i++) printf(" %d ",q[i]); for(i=front;i<max;i++) printf(" %d ",q[i]); } } } void insertrear() { if((front==rear+1)((front==0)&&(rear==max-1))) printf("QUEUE IS FULL"); else { if(rear==max-1) rear=0; else rear++; if(front==-1) front++; printf("ENTER THE ELEMENT TO BE INSERTED :"); scanf("%d",&q[rear]); printf("\ QUEUE AFTER INSERTION :"); print(); } } void delfront() { if(front==-1) printf("QUEUE EMPTY"); else { printf("ELEMENT DELETED : %d",q[front]); if(front==rear) { front=-1; rear=-1; } else if(front==max-1) front=0; else front++; printf("\ QUEUE AFTER DELETION :"); print(); } } void insertfront() { if((front==rear+1)((front==0)&&(rear==max-1))) printf("QUEUE IS FULL"); else { if(front==-1) { front++; rear++; } else if(front==0) front=max-1; else front--; printf("ENTER THE ELEMENT TO BE INSERTED :"); scanf("%d",&q[front]); printf("\ QUEUE AFTER INSERTION :"); print(); } } void delrear() { if(front==-1) printf("QUEUE EMPTY"); else { printf("ELEMENT DELETED : %d",q[rear]); if(front==rear) { front=-1; rear=-1; } else if(rear==0) rear=max-1; else rear--; printf("\ QUEUE AFTER DELETION :"); print(); } } void main() { int ch; clrscr(); do { printf("\n1) INSERTION AT FRONT \n2)INSERTION AT REAR\n3.DELETEION AT FRONT\n4.DELETION AT REAR\n "); printf("\n ENTER CHOICE "); scanf("%d",&ch); switch(ch) { case 1:insertfront(); break; case 2:insertrear(); break; case 3:delfront(); break; case 4:delrear(); break; default :printf("WRONG CHOICE"); break; } }while(ch>=1&&ch<=4); getch(); }