I just wanted to know what would happen if you abuse the CharStack class by pop()ing more characters than you push()? Would it be an error of out of exception or something else.

Recommended Answers

All 5 Replies

Read the API docs for the class.

Member Avatar

Besides... Your code should be checking not to pop() if there are 0 elements in your stack.

Member Avatar

Agreed... I don't find any documentation about a class called CharStack.
A stack (of any type) is a list construct the programmer must create via array.

So this is a class that you have written / must write? In that case the answer to your original Q is "that's up to you". Throwing an Exception would be a reasonable thing to do, because it would be an error.

Be a part of the DaniWeb community

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