- 1
how can i write a function which return the number of elements of a stack?
3 Answers
+ 1
Either make it traverse the whole stack (while next doesn't equal null) and increment your counter variable everytime you pass on a node, or just keep track of your stack while adding/deleting with a count variable in the stack's class.
+ 1
I didn't say you'll return the elements (it's a pointer btw) you'll only count it..
count = 0
while condition do
count = count + 1
end while
return count
- 1
Without node ,,,? How can i return numbers not element?