Urgenthomework logo
UrgentHomeWork
Live chat

Loading..

Queues Data Structure Homework Help

Queue is a data structure that maintain "First In First Out" (FIFO) order. In encoding, queue is generally utilized like a data structure for BFS (Breadth First Search).

Queue A first-in, first-out (FIFO) data structure.

Queues Data Structure Help

Queue Operations

Operations on queue Q are :

  • enqueue : insert item at the back of queue Q
  • dequeue : return (and virtually remove) the front item from queue Q
  • init : intialize queue Q, reset all variables.

Implementation In C

#include<studio.h>
#define QUEUE_SIZE100
typedefstruct{int q[QURUE_SIZE];
int first, last;
int count;
}queue;
void init_queue(queue*q)
{ q->first=0;
q->last=QUEUE_SIZE-1;
q->count=0;}
void enqueue (queue*q,int x){
q->last=(q->last+1)%QUEUE_SIZE;
q->q[q->last]=x;
q->count=q->count+1;} int dequeue(queue*q){ intx=q->q[q->first];
q->first=(q->first+1)%QUEUE_SIZE;
q->count=q->count-1;
return x;}
int main(){
queue q;
init_queue(&q);
enqueue(&q,1);
enqueue(&q,2);
enqueue(q3,3);
while(q.count)
printf(%d\n", dequeue(&q));
return 0;}
Queues Data Structure Homework Help
Copyright © 2009-2023 UrgentHomework.com, All right reserved.