683 views
0 votes
0 votes
Let's say stack is implemented as Link List, then what will pop() function will return to the calling function?

The popped element or the what, because while popping at the end we are freeing up the space in which TOS element is present whic needs to be popped!

2 Answers

2 votes
2 votes
It is not very clear what you are trying to ask.

All I understood was which element does linked list return when a stack is implemented using it.

For optimum time complexity, Push and Pop operations are done on the node which is pointed by the Head of the linked-list.

So when Pop is called the first node address is copied to another pointer and the Head will point to the next node. Then the node value can be returned and space freed- up.

Related questions

1 votes
1 votes
1 answer
1
radha gogia asked Jul 24, 2018
1,309 views
Suppose one character at a time comes as an input from a string of letters . There is an option either to 1) print the incoming letter or to 2) put the incoming letter on...
1 votes
1 votes
1 answer
3
3 votes
3 votes
3 answers
4
Ibtisam Sayyad asked Jan 12, 2018
7,864 views
What are the minimum enqueue and dequeue operations needed to perform pop operation for a stack which is implemented with two queues if there are already 10 elements in t...