60.7k views
2 votes
void main() Stack aStk; //object of type Stack aStk.push("Tim",2222); aStk.push("Jan",1111); aStk.push("Elize",0111); system(pause); Complete these tasks: Finish the push() method Implement the pop(. Give the stackTop() prototype decalration and implement the method to display the top element of the stack Add at least 2 calls to the new methods implemented in the main() Determine the Big-O of stack implementation.

User DRich
by
8.2k points

1 Answer

3 votes

Final answer:

The question is about the implementation of the Stack data structure in programming. The student needs to implement the push, pop and stackTop methods for the Stack. The Big-O complexity for these operations is O(1).

Step-by-step explanation:

In a Stack implementation, three primary operations are performed which are push, pop and stackTop. Push is used to add elements to the top of the stack. The implementation of push method could be something like this:

void push(string name, int number) { top++; s[top].name = name; s[top].number = number; }

Second function, pop(), is used to remove elements from the top of stack. The implementation for this function would be:

void pop() { if(top==-1) cout<<"Stack is empty."; else top--; }

The stackTop() method is used to get the top element of the stack. The implementation would look like:

void stackTop() { if(top==-1) cout<<"Stack is empty."; else cout<

User Mjordan
by
8.2k points