Hi everyone I am trying to get this done and it is not happening :to implement the method for the is Empty and is Full. I am suppose to check for an empty stack and check for a full stack

But I am not getting it? Can someone see something I am not seeing:

Basic data structure to provide LIFO (last-in-first-out) functionality

class SimpleStack {
private int top;
private int stackSize;
private char []buffer;

// Your default constructor
SimpleStack() {
top = -1; // Set top of the stack to -1 to indicate an empty stack
stackSize = 5; // Set the default size of the stack to 5
buffer = new char[5]; // Buffer (container) to hold items
}

// Your parameterized (convinient) constructor
SimpleStack(int size) {
top = -1;
stackSize = size;
}

// push method to place an item on top of the stack
public void push(char item) {
buffer[++top] = item;
}

// pop method to return the item on top of the stack
public char pop() {
return buffer[top--];
}

// Checks to see if the stack is empty

drinkgoodjava: public boolean isEmpty() {
// Logic: Stack is empty if top has reached -1.
// This method should return "true" if stack is empty and "false" otherwise.
// Note that you need to write the code in here.
}

// Checks to see if the stack is full
public boolean isFull() {
// Logic: Stack is full if "top" has reached stackSize - 1
// This method should return "true" if stack is full and "false" otherwise.
// Note that you need to write the code in here.
}
}


// Checks to see if the stack is full
public boolean isFull() {
// Logic: Stack is


WHAT AM I MISSING HERE??????

public boolean isEmply(){
if(top == -1){
   return true;
} else {
  return false;
}
}

public boolean isFull(){
 if((stackSize - 1)  == top){
  return true;
}
else {
  return false;
}
}

also change your push to use top++

Hello !!!!

I need help to write code for the following methods using private data member.
1) Clear
2) Full
3) Size

Thank you in advance.

public boolean isEmply(){
if(top == -1){
   return true;
} else {
  return false;
}
}

or even...

public boolean isEmpty {
   return top == -1;
}

This is a 6-month old thread. It is better if you didn't get your answer here to start a new thread.

Also this thread has already enough piece of code to get you started. Start a new Thread with some real questions. People might get the wrong idea with the way you asked for help.
Ask specific questions after showing some code of yours

How about the push, It throws an exception , index out of bounds when more then required is pushed. How can it return false instead.

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.