Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The Stack is a LIFO data structure. That’s Last In First Out. We have already im

ID: 3678724 • Letter: T

Question

The Stack is a LIFO data structure. That’s Last In First Out. We have already implemented Stacks in class. What I’d like you to do is to implement a Queue - This is a FIFO data structure. The requirements are:

Implement it as an ADT supporting the push, isEmpty(), pop and peek() operations

However, data should internally be stored using an array, not a list.

Most importantly, all operations ought to complete in fixed (constant) time. This means the time to push or pop should NOT monotonically increase with increasing Queue size.

Here are the rules:

Keep it all constant time. no linear time…

Here’s the deal:

post a correct, elegant, concise and solution

Explanation / Answer

//implement queue using array #include //MAX ARRAY SIZE #define MAXIM 100 //here size of queue array is set to 100 int array[MAXIM]; //Initially rare and front points to -1 in queue and at this time queue is empty int rear = - 1; int front = - 1; //execution starts here main() { int choice; while (1) { printf("1.push element to queue "); printf("2.pop element from queue "); printf("3.Display all elements of queue "); printf("4.Quit from program "); printf("Enter your choice : "); scanf("%d", &choice); switch (choice) { case 1: push(); break; case 2: pop(); break; case 3: display(); break; case 4: exit(1); default: printf("Please enter the right choice "); } //end of switch condition } //end of while loop } //end of main functiom //queue filling operation push() { int add_item; if (rear == MAXIM - 1) printf("Queue FULL "); else { if (front == - 1) front = 0; printf("Inset the element in queue : "); scanf("%d", &add_item); rear = rear + 1; array[rear] = add_item; } }//end of insert function pop() { if (front == - 1 || front > rear) { printf("Queue empty "); return ; } else { printf("Element deleted from queue is : %d ", array[front]); front = front + 1; } } //end of delete function display() { int i; if (front == - 1) printf("Queue is empty "); else //display elements of queue { printf("Queue is : "); for (i = front; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote