Homeassignment no.2 - HinaUmer123/assignment-of-java GitHub Wiki

package Stack;

public class Stack{

	public int[] stk = new int[10];

	public int top;

public Stack()

{

this.top= -1;

}

boolean isempty()

{

	if(top==-1)

	return true; //stack is empty

	else

	{


	
	return false; //stack has some elements


    }


}

boolean isfull()

{

	if(top==(10 - 1))

	return true; //stack is full

	else

	{

		return false;  //stack is not full

	}

}





void push(int num)

{

	if(isfull()== true)

	System.out.print("stack is full, no more elements cen be added");

	else

	{

	
	
		top = top+1;

		stk[top] = num;

	}
}


int pop()


{

        int num;

	if(isempty()== true) // 1 is use for true

	System.out.print("stack is empty, not possible to pop any elements");


	else

	{

		num = stk[top];

		top = top-1;

		return num;



	}

            return num;

}

void display()

{
	if(isempty()== true)

	System.out.println("stack is empty");

	else

	{
		for(int i = top; i>=0; i--)

		System.out.print(stk[i] + "  ");

		
	}
}
	

public static void main(String[] args) {
    
  Stack stObj = new Stack();

stObj.push(1);

stObj.push(2);

stObj.push(30);

stObj.push(40);

stObj.push(100);
    
    stObj.display();

     System.out.println();

    stObj.pop();
      
    stObj.display();

    // TODO code application logic here
}

}