Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions Exercise_1.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,55 @@ class Stack {
int a[] = new int[MAX]; // Maximum size of Stack

boolean isEmpty()
{
//Write your code here
{
if(top !=0) return false;

return true;
}

Stack()
{
//Initialize your constructor
top = 0;
}

boolean push(int x)
{
//Check for stack Overflow
//Write your code here
if(top == MAX){
return false;
}

top +=1;
a[top] = x;
return true;
}

int pop()
{
//If empty return 0 and print " Stack Underflow"
//Write your code here

if(top == 0){
System.out.println("Stack Underflow");
return 0;
}

int num = a[top];
top--;
return num;
}

int peek()
{
//Write your code here
if(top == 0){
return 0;
}

int num = a[top];

return num;
}
}

Expand Down