Question: Program Instructions: Create a node class/struct. Create a queue class/struct. Members: Node - a node that tracks the front of the queue. Node - a
Program Instructions: Create a node class/struct. Create a queue class/struct. Members: Node - a node that tracks the front of the queue. Node - a node that tracks the end of the queue. Count - indicates how many items are on the queue. Methods: En-queue - Accepts a number and adds to the end of the queue. De-queue - Returns a number from the front of the queue. - If the queueis empty, emit an error indicating the queueis empty. IsEmpty - Returns a boolean indicating if the queue is empty.
Can someone help me change my Linked Stacked Based Program into the instructions for Linked Queue Based Program above?
#include
struct node { int info; struct node *link; }*top;
class based_stack { public: node *push(node *, int); node *pop(node *); void traverse(node *); based_stack() { top = NULL; } };
int main() { int pick, object; based_stack bar; while (1) { cout << "Press #1. Push" << endl; cout << "Press #2. Pop" << endl; cout << "Press #3. Traverse" << endl; cout << "Press #4. Exit" << endl; cout << "Enter an option"; cout << " " << endl; cin >> pick; switch (pick) { case 1: cout << "Enter value to be pushed into the stack: "; cin >> object; top = bar.push(top, object); break; case 2: top = bar.pop(top); break; case 3: bar.traverse(top); break; case 4: exit(1); break; default: cout << "Invalid Option" << endl; } } return 0; }
// Push
node *based_stack::push(node *top, int item) { node *temp; temp = new (struct node); temp->info = item; temp->link = top; top = temp; return top; }
// Pop
node *based_stack::pop(node *top) { node *temp; if (top == NULL) cout << "The stack is Empty" << endl; else { temp = top; cout << "Element has been Popped " << temp->info << endl; top = top->link; free(temp); } return top; }
// Traverse void based_stack::traverse(node *top) { node *pointer; pointer = top; if (top == NULL) cout << "The stack is empty" << endl; else { cout << "The stack elements are" << endl; while (pointer != NULL) { cout << pointer->info << endl; pointer = pointer->link; } } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
