Stack algorithm is not working pefectly in Java

You didn’t initialize the fields in your Stack class. You should read about Constructors in Java, since it seems you are new to programming.

The reason the program says the stack is full is that, if not initialized, the default values for type int is 0, so n in your stack class is 0.

Leave a Comment