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

Read the API docs for the class.

Jump to Post

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

Jump to Post

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.

Which CharStack class would that be?

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 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.