Question

A limited-sized Queue ADT is an abstract data type that has a limit on the length of the queue. It can be created with a static array of size N, where Nis the maximum length of the array. In C, this structure can be defined as follows: type def struct int data array of the data on the queue you may add other attributes here but use as few as possible queue t Write an (efficient) pseudocode for the implementation of each of the following function prototypes (proper C code will also be accepted) void print (Q) prints the entire queue Qfrom front to back int enqueue (Q, x) enqueues the element x into queue Q (if unsuccessful, return -1) int de queue (Q) dequeues the next integer from front of the queue (if unsuccessful, return null) int is Empty (Q) returns 1 (true) or 0 (false) depending on emptiness of the queue Q unsigned int size (Q) returns the number of items currently in the queue In your final solution, you may add any extra attributes that you feel is needed for this question but you must use as few extra attributes as possible and your algorithm must be as efficient as possible (in terms of big-O analysis)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<conio.h>
#include<stdio.h>
#define max 5
int queue[max],front=0,rear=0;
int menu();
void enqueue();
void dequeue();
void display();
void isempty();
void size_();
void main()
{
int ch;
printf("\nQueues using Arrays\n");
do
{
ch=menu();
switch(ch)
{
case 1: enqueue();
break;
case 2: dequeue();
break;
case 3: display();
break;
case 4: isempty();
break;
case 5: size_();
break;
default:printf("\n Please enter a valid choice!!");
}
}while(1);
}

int menu()
{
int ch;
printf("\n1.ENQUEUE \n2.DEQUEUE \n3.DISPLAY \n4.isempty \n5.size \n");
printf("\nEnter your Choice:");
scanf("%d",&ch);
return ch;
}

void enqueue()
{
int element;
if(rear==max)
{
printf("\nOverflow!!");
}
else
{
printf("\nEnter Element:");
scanf("%d",&element);
queue[rear++]=element;
printf("\n %d Enqueued at %d",element,rear);
}

}

void dequeue()
{
if(rear==front)
{
printf("\nUnderflow!!");
}
else
{
front++;
printf("\nElement is Dequeued from %d",front);
}
}
void display()
{
int i;
if(front==rear)
{
printf("\nQueue is Empty!!!");
}
else
{
printf(" \n");
for(i=front;i<max;i++)
{
printf(" | %d ",queue[i]);
}
printf("|");
}
}
void isempty()
{
if(front==rear)
printf("THE QUEUE IS EMPTY \n");
}

void size_()
{
int count=0,i;
if(rear==1)
count=1;
else if(front==rear)
count=0;
else{
for(i=front;i<=rear;i++)
count=count+1;}
printf("%d\n",count);
}

OUTPUT:

Queues using Arrays 1. ENQUEUE 2. DEQUEUE 3.DISPLAY 4. isempty 5.size Enter your choice:5 1. ENQUEUE 2. DEQUEUE 3.DISPLAY 4.2 Enqueued at 1 1.ENQUEUE 2. DEQUEUE 3.DISPLAY 4. isempty 5.size nter your Choice:1 Enter Element: 4 4 Enqueued at 2 1.ENQUEU1. ENQUEUE 2. DEQUEUE 3. DISPLAY H.isempty 5.size Enter your Choice:2 Element is Dequeued from2 1. ENQUEUE 2. DEQUEUE 3.DISPL

Add a comment
Know the answer?
Add Answer to:
A limited-sized Queue ADT is an abstract data type that has a limit on the length...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Suppose we have an array-based queue (circular buffer) of size 6: int data[6]; int front =...

    Suppose we have an array-based queue (circular buffer) of size 6: int data[6]; int front = 0, back = 0; void enqueue(int x) { data[back] = x; back = (back + 1) % 6; } void dequeue() { front = (front + 1) % 6; } and we perform the following series of queue operations: enqueue(1); dequeue(); enqueue(2); dequeue(); enqueue(7); enqueue(3); enqueue(5); dequeue(); dequeue(); enqueue(4); enqueue(6); Write the state of the queue array after each operation, and at the end,...

  • Collect/finish the Java code (interface and the complete working classes) from lecture slides for the for...

    Collect/finish the Java code (interface and the complete working classes) from lecture slides for the for the following ADT: 3) Queue ADT that uses an array internally (call it AQueue) Make sure you keep the same method names as in the slides (automatic testing will be performed)! Make sure your classes implement the corresponding interfaces. Put your classes in a package called cse11. Try to make the code robust and try to use generics. The Queue ADT The Queue ADT...

  • Design and implement a class Q that uses Q.java as a code base. The queue ADT...

    Design and implement a class Q that uses Q.java as a code base. The queue ADT must use class LinkedList from Oracle's Java class library and its underlying data structure (i.e. every Q object has-a (contains) class LinkedList object. class Q is not allowed to extend class LinkedList. The methods that are to be implemented are documented in Q.java. Method comment blocks are used to document the functionality of the class Q instance methods. The output of your program must...

  • Create a Java code that includes all the methods from the Lecture slides following the ADTs...

    Create a Java code that includes all the methods from the Lecture slides following the ADTs LECTURE SLIDES Collect/finish the Java code (interface and the complete working classes) from lecture slides for the following ADTS: 4) Queue ADT that uses a linked list internally (call it LQueue) Make sure you keep the same method names as in the slides (automatic testing will be performed)! For each method you develop, add comments and estimate the big-O running time of its algorithm....

  • typedef struct queue * Queue; Queue queueCreate(int maxSize); void enqueue(Queue q, int item); int queueFront(Queue q);...

    typedef struct queue * Queue; Queue queueCreate(int maxSize); void enqueue(Queue q, int item); int queueFront(Queue q); int dequeue(Queue q); int queueSize(Queue q); void queueDestroy(Queue q)Exercise 1: Writing Assert Based Black Box Unit Tests for a Queue For this exercise you will need a copy of Queue.h, the queue interface for this exercise. You can download it or use the following command to copy it into your current directory cp «dp1091/public_html/2012/tlb/11/Queue.h. And a copy of the testQueue.c, the testing code we...

  • Are based on the following Queue class code segment class QueueFull {/* Empty exception class */};...

    Are based on the following Queue class code segment class QueueFull {/* Empty exception class */}; Class Queue Empty {/* Empty exception class */}; struct Node//Node structure int data;//Holds an integer Node* next;//Pointer to next node in the queue}; Class Queue//Linked node implementation of Queue ADT {Private: Node* front;//Pointer to front node of queue Node* rear;//pointer to last node of queue Public: Queue ()://default constructor initializes queue to be empty -Queue ();//Deallocates all nodes in the queue Void Add (int...

  • // =================== Support Code ================= // Queue // // // // - Implement each of the functions to create a working circular queue. // - Do not change any of the function declarations // ...

    // =================== Support Code ================= // Queue // // // // - Implement each of the functions to create a working circular queue. // - Do not change any of the function declarations //   - (i.e. queue_t* create_queue(unsigned int _capacity) should not have additional arguments) // - You should not have any 'printf' statements in your queue functions. //   - (You may consider using these printf statements to debug, but they should be removed from your final version) // ==================================================...

  • Array-based Queue Lecture 6 Two Class Exercises | Class Exercise #1 - Create an array-based queue that holds value...

    Array-based Queue Lecture 6 Two Class Exercises | Class Exercise #1 - Create an array-based queue that holds values of double data type. 1.) Create a program that produces the following output OUTPUT: Q Quit Enter your choice: e Enter an item: 1.1 E Enqueue D Dequeue s-show queue ← showMenuO function called in main) OQuit // screen clears-.. continue enqueuing.screen clearing with each iteration Enter your choice: e Queue is full. E Enqueue D Dequeue s Show queue 0...

  • CODE IN C Objectives: Queue operations. Data structure: typedef struct { int width; int heig...

    CODE IN C Objectives: Queue operations. Data structure: typedef struct { int width; int height; }Rect; typedef struct node { Rect* r; struct node* next; }Node; typedef struct { Node* head; Node* tail; }Queue; Specification: In this lab six Queue-related operation functions need to be implemented by using the given function prototypes and data structures. 1. List* createQueue(void); This function initializes an empty “Queue” with the “Queue” data structure and returns an empty queue. 2. int enQueue(List*); This function receives...

  • CODE IN C Objectives: Queue operations. Data structure: typedef struct { int width; int height; }Rect;...

    CODE IN C Objectives: Queue operations. Data structure: typedef struct { int width; int height; }Rect; typedef struct node { Rect* r; struct node* next; }Node; typedef struct { Node* head; Node* tail; }Queue; Specification: In this lab six Queue-related operation functions need to be implemented by using the given function prototypes and data structures. 1. List* createQueue(void); This function initializes an empty “Queue” with the “Queue” data structure and returns an empty queue. 2. int enQueue(List*); This function receives...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT