answersLogoWhite

Top Answer
User Avatar
Wiki User
Answered 2010-12-05 15:29:35
ARRAY-BASED CIRCULAR QUEUE#include#include

class person

{

public:

int arr_tym, trans_tym, wait_tym, deprt_tym;

};

class queue

{

private:

person data[5];

int front , back , count;

public:

queue()

{

front=0;

back=0;

count=0;

}

void Front()

{

cout<<" \n The arrival time of the first customer is :"<

cout<<" \n And the transaction time of the first customer is :"<

}

void enqueue(int a_tym, int t_tym)

{

if(count==5)

cout<<"\n The queue is full. \n";

else if(count<5)

{

data[back].arr_tym=a_tym;

data[back].trans_tym=t_tym;

count++;

if(back==4)

back=0;

else if(back<4)

back++;

}

Front();

}

void dequeue()

{

if(count==0)

cout<<"\n The queue is already empty. \n";

else if(count>0)

{

data[front].arr_tym=0;

data[front].trans_tym=0;

if(front<4)

front+=1;

else if(front==4)

front=0;

cout<<"\n The element has been deleted. \n";

count--;

Front();

}

}

void Is_Empty()

{

if(count==0)

cout<<"\n The queue is empty. \n";

else if(count<5&&count>0)

cout<<"\n The queue has "<

else if(count==5)

cout<<"\n The queue is full. \n";

}

void cal_w8_tym()

{

for(int i=front;i<5;i++)

{

if(i==1)

{

data[i].deprt_tym=data[i].arr_tym+data[i].trans_tym;

data[i].wait_tym=0;

}

else

{

if(data[i].deprt_tym

{

data[i].deprt_tym=data[i].arr_tym+data[i].trans_tym;

data[i].wait_tym=0;

}

else

{

data[i].deprt_tym=data[i-1].deprt_tym+data[i].trans_tym;

data[i].wait_tym=data[i-1].deprt_tym-data[i].arr_tym;

}

}

}

}

void display()

{

cout<<"\n\tARRIVAL TIME\tTRANSACTION TIME\tWAITING TIME\tDEPARTING TIME\n";

for(int i=front;i<5;i++)

{

cout<<"\n\t"<

cout<<"\t"<

cout<<"\t"<

cout<<"\t"<

}

}

void avg_w8_tym()

{

}

};

void main()

{

queue q;

int arr_time,trans_time;

char opt;

do

{

cout<<"\n Enter arrival time of the customer: ";

cin>>arr_time;

cout<<" \n Enter transaction time of the customer: ";

cin>>trans_time;

q.enqueue(arr_time,trans_time);

cout<<"\n Do you want to continue? ";

cin>>opt;

}while(opt=='y');

q.Front();

q.dequeue();

q.Is_Empty();

q.dequeue();

q.cal_w8_tym();

q.display();

}

LINKED LIST BASED CIRCULAR QUEUE

#include

class node

{

public:

int data;

node* link;

};

class queue

{

node* front;

node* back;

public:

queue()

{

front=NULL;

back=NULL;

}

void enqueue(int d)

{

node* ptr;

ptr=new node;

ptr->data=d;

ptr->link=NULL;

if(front==NULL)

{

front=ptr;

back=ptr;

}

else

{

back->link=ptr;

back=back->link;

}

}

void dequeue()

{

node* ptr;

ptr=front;

if(front==NULL)

cout<<"\n Nothing can be deleted. \n";

else

{

ptr=front;

front=front->link;

delete ptr;

ptr=NULL;

cout<<"\n The first element has been deleted.\n";

Front();

}

}

void If_Empty()

{

if(front==NULL)

cout<<"\n The queue is empty.\n ";

}

void Front()

{

if(front!=NULL)

cout<<"\n The first element is "<data<

}

};

void main()

{

queue q;

int data;

char opt;

do

{

cout<<" Enter your data:\t";

cin>>data;

q.enqueue(data);

cout<<"\n Do you want to continue:\t";

cin>>opt;

}while(opt=='y'opt=='Y');

q.Front();

q.dequeue();

q.If_Empty();

q.dequeue();

q.dequeue();

q.If_Empty();

q.dequeue();

}

001
๐Ÿ™
0
๐Ÿคจ
0
๐Ÿ˜ฎ
0
๐Ÿ˜‚
0
User Avatar

Your Answer

Loading...

Still Have Questions?

Related Questions

Operations performed in singly linked list using C program?

The main operations on singly linked list are: 1:-Insertion 2:-Deletion 3:-Searching 4:-Display Insertion can be done in done ways: 1)Insertion at beginning 2)Insertion at end 3)Inserting at a specified position Deletion can be performed in 3 ways: 1)Deletion from beginning 2)Deletion from end 3)Deletion from a specified position.


What is the difference betweens deletion and insertion?

Deletion is nothing but eliminating and insertion is adding.


What are the operations in singly linked lists?

Operations that are performed on a singly linked list are- 1. Traversal of complete list (Displaying all data elements) 2. Insertion of element at beginning. 3. Insertion of element at end. 4. Insertion of element at specified position. 5. Deletion of element from beginning. 6. Deletion of element from end. 7. Deletion of element from specified position.


Difference between circular queue and De queue?

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)


What is the advantage of a circular queue over a linear queue in queue data structure?

A standard queue suffers from a rebuffering problem during dequeue operations. By making the queue circular and linking the head to the tail, this alleviates the problem and allows insertion and deletion in constant time.


What is a circular queue in data structure?

A circular queue is a Queue but a particular implementation of a queue. It is very efficient. It is also quite useful in low level code, because insertion and deletion are totally independant, which means that you don't have to worry about an interrupt handler trying to do an insertion at the same time as your main code is doing a deletion.


Which is not a frameshift mutation substitution insertion deletion or point mutation?

frameshift- deletion and insertion point mutation- sustitution


Program for insertion and deletion operations in AVL tree?

This has to do with computer programing. You may want to talk with someone who has the knowledge to get the right program.


What are the applications of data structures?

Data structures could be used to implement an efficient database. Linked lists for example will optimize insertion and deletion for ordered lists.


What are the type of mutations?

Insertion, Deletion, and Substitution.


What are the causes of frameshift mutation?

Deletion or Insertion


What are insertion substitution and deletion?

due i have problem


What is a deque?

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)


Queue and algorithm to perform queue operations?

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/


Difference between queue and a circular queue?

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.


Difference between queue and circular queues?

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. 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


How is linear queue compared with circular queue?

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.


What do you understand by deque?

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)


What occurs in base insertion mutations and base deletion mutations?

In insertion mutations, an extra base pair is added, and in a deletion, a base pair is taken out (omitted).


What are three types of mutations?

Insertion, deletion, and substitution.


What are the 3 types of mutations?

substitution deletion insertion


What are the three types of mutation?

Substitution, Insertion, Deletion


What do insertion and deletion have in common?

Both of them affect the length.


Circular queue in linear data structure?

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.


Why you can use double ended queue?

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)