Question

C++ functions using linked list A templated stack class that stores type T with the following...

C++ functions using linked list

A templated stack class that stores type T with the following public functions:

template <class T>

class Stack{

- void Push(T t) - adds t to the top of the stack

- T Pop() - asserts that the stack is not empty then removes and returns the item at the top of the stack.

};

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE

template <class T>

void Stack::Push(T t)

{

Node<T>* temp;

temp = new Node();

temp->data = data;

temp->next = top;

top = temp;

}

template <class T>

T Stack::pop() {

Node<T* temp;

if (top == NULL) {

cout << "\nStack Underflow" << endl;

exit(1);

}

else {

temp = top;

top = top->next;

temp->next = NULL;

delete temp;

}

}

Add a comment
Know the answer?
Add Answer to:
C++ functions using linked list A templated stack class that stores type T with the following...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT