A limited-sized Queue ADT is an abstract data type that has a limit on the lengt
ID: 3803977 • Letter: A
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 N is the maximum length of the array. In C, this structure can be defined as follows: typedef 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 Q from front to back. int enqueue (Q, x) - enqueues the element x into queue Q (if unsuccessful, return -1) int* dequeue (Q) - dequeues the next integer from front of the queue (if unsuccessful, return null) int isEmpty(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-0 analysis).Explanation / Answer
Answer:
#include<iostream>
using namespace std;
struct node
{
int info;
node *later;
}*front_end = NULL,*rear_end = NULL,*p = NULL,*node_pointer = NULL;
void push(int value)
{
node_pointer = new node;
node_pointer->info = value;
node_pointer->later = NULL;
if(front_end == NULL)
{
front_end = rear_end = node_pointer;
rear_end->later = NULL;
}
else
{
rear_end->later = node_pointer;
rear_end = node_pointer;
rear_end->later = NULL;
}
}
int remove()
{
int value;
if(front_end == NULL)
{
cout<<" queue is empty ";
}
else
{
p = front_end;
value = p->info;
front_end = front_end->later;
delete(p);
return(value);
}
}
int main()
{
int n,c = 0,value;
cout<<"Enter the number of values to be pushed into queue ";
cin>>n;
while (c < n)
{
cout<<"Enter the value to be entered into queue ";
cin>>value;
push(value);
c++;
}
cout<<" Deleted Values ";
while(true)
{
if (front_end != NULL)
cout<<remove()<<endl;
else
break;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.