0% found this document useful (0 votes)
21 views2 pages

Oops 2

oops

Uploaded by

19 038 Sahal H
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views2 pages

Oops 2

oops

Uploaded by

19 038 Sahal H
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import java.util.

Scanner;
interface MyStack
{
public void popO;
public void push();
public void display();
}
class StackArray implements MyStack
{
final static int n=5;
int stack()=new int[n];
int top=-1;
public void push()
{
Scanner in;
try
{
in=new Scanner(System.in);
if(top==(n-1))
{
System.out.println("Stack Overflow");
return;
}
else
{
System.out.println("Enter the element");
int elesin.nextInt();
stack[++top]=ele;
}
}
catch(Exception e)
{
System.out.println("e");
}
public void pop()
{
if(top<0)
{
System.out.println("Stack underflow");
return;
}
else
{
int popper-stack[top];
top-
System.out.println("Popped element:" +popper);
public void display
{
if(top<0)
{
System.out.println("Stack is empty');
return;
)
else
{
String str="";
for(int i=0; i<=top; i++)
str=str+""+stack[i]+" -->";
System.out.println("Elements are:"+str);
}
}
class StackAdt
{
public static void main(String arg[])
{
Scanner in= new Scanner(System.in);
System.out.println("Implementation of Stack using
Array"); StackArray stk=new StackArray(); int ch=0;
do
{
System.out.println("1.Push 2.Pop 3.Display 4.Exit");
System.out.println("Enter your choice:");
ch-in.nextInt();
switch(ch)
{
case 1:
stk.push();
break;
case 2:
stk.pop();
break;
case 3:
stk.display();
break;
case 4:
System.exit(0);
}
}
while(ch<4);
}
}

You might also like