I have just started to learn about stacks and have been scouring the net for information. I am having trouble coming up with an answer for this question:

Suppose you were asked to add a function CountStack to the stack ADT that would return the number of items in the stack. Explain how this function would work for an array-based stack and what would change for a pointer-based stack.

Can anyone help me understand the differences?
Any help is much appreciated.

Recommended Answers

All 2 Replies

Assuming some things, the difference is traversing a linked list to a null pointer and returning the index of the top of the stack.

checking time

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.