Stack Flashcards

1
Q

Stack push

A
void push(T value)
{
    if (isFull())
    {
        cout << "Stack is already full" << endl;
        return;
    }
    topIndex++;
    stack[topIndex] = value;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Stack pop

A
    void pop()
    {
        if (isEmpty())
        {
            cout << "Stack is already empty" << endl;
            return;
        }
        topIndex--;
    }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Stack top/peek

A
    T top() const
    {
        if (isEmpty())
        {
            cout << "Stack is empty" << endl;
            return T();
        }
        return stack[topIndex];
    }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Stack isEmpty

A
    bool isEmpty() const
		{
               return topIndex == -1;
    }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Stack isFull

A
bool isFull() const
{
                return topIndex == MAXSIZE - 1;
 }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Stack clear

A
    void clear()
		{
                            topIndex = -1;
       }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Stack display

A
template <typename T>
void display(const Stack<T>& s)
{
    if (s.isEmpty()) {
        cout << "Stack is empty" << endl;
        return;
    }

    Stack<T> temp = s;
    while (!temp.isEmpty()) {
        cout << temp.top() << " ";
        temp.pop();
    }
    cout << endl;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly