Open main menu

CDOT Wiki β

Changes

Q1 A linked list question

26 bytes removed, 17:33, 4 August 2010
no edit summary
In this question, you must use a linked list like structure to implement the object. If you use an array or even a dynamic array, no marks will be awarded.<br><br>
Write a template class Stack<T> where T is any data type that can be constructed without any arguments and can be copied using the assignment operator. You can also pass any instance of T into a function by value.<br><br>
A stack is a data structure that is LIFO. In other words, the last thing added will be the first thing removed. (see sample main)<br><br>
When a Stack is first instantiated, it is empty.<br><br>
A Stack has the following public member functions:<br><br>
'''isempty''' - this function takes no arguments and returns a bool. If the stack is empty, return true, otherwise return false<br><br>
'''push '''- this function takes an instance of the unknown data type T as its only parameter and returns nothing. It will put the data onto the stack.<br><br>
'''pop ''' - this function takes no arguments and returns an instance of the unknown data type T. It will remove and return the last piece of data that was added. If the stack isempty when this function is called, the function should throw the string "empty stack" as an exception.<br><br>
Sample main: