A technical blog covering programming problem solutions, contest strategies, algorithms, data structures, and handy tech tools for developers.
Code : Stack Using LL
Get link
Facebook
X
Pinterest
Email
Other Apps
-
You need to implement a Stack class using a linked list.
The data members should be private.
Implement the following public functions :
1. Constructor -
Initialises the data member (i.e. head to null).
2. push :
This function should take one argument of type T and has return type void. This function should insert an element in the stack. Time complexity should be O(1).
3. pop :
This function takes no input arguments and has return type T. This should removes the last element which is entered and return that element as an answer. Time complexity should be O(1).
4. top :
This function takes no input arguments and has return type T. This should return the last element which is entered and return that element as an answer. Time complexity should be O(1).
5. size :
Return the size of stack i.e. count of elements which are present ins stack right now. Time complexity should be O(1).
6. isEmpty :
Checks if the stack is empty or not. Return true or false.
Comments
Post a Comment
Please give us your valuable feedback