import java.io.*;
class Stack
{
double Arr[]=new double[5];
double x;
static int p=-1;
public void Push(double x)
{
p++;
Arr[p]=x;
}
public void Pop()
{
if(p==-1)
System.out.println("stack underflow");
else
p--;
}
public static void main(String args[])
{
Stack ob= new Stack();
int ch=0;
double b=0.0;
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Stack operations");
System.out.println("1.push element");
System.out.println("2.pop element");
System.out.println("3.Exit");
try
{
do
{
System.out.println("Enter your choice");
ch=Integer.parseInt(bf.readLine());
if(ch!=1&ch!=2&ch!=3)
System.out.println("enter the number from given choices");
switch(ch)
{
case 1:
if(p==4)
System.out.println("stack overflow");
else
{
System.out.println("enter the element to push");
b=Double.parseDouble(bf.readLine());
ob.Push(b);
break;
}
case 2:
ob.Pop();
break;
}
}while(ch!=3);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
class Stack
{
double Arr[]=new double[5];
double x;
static int p=-1;
public void Push(double x)
{
p++;
Arr[p]=x;
}
public void Pop()
{
if(p==-1)
System.out.println("stack underflow");
else
p--;
}
public static void main(String args[])
{
Stack ob= new Stack();
int ch=0;
double b=0.0;
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Stack operations");
System.out.println("1.push element");
System.out.println("2.pop element");
System.out.println("3.Exit");
try
{
do
{
System.out.println("Enter your choice");
ch=Integer.parseInt(bf.readLine());
if(ch!=1&ch!=2&ch!=3)
System.out.println("enter the number from given choices");
switch(ch)
{
case 1:
if(p==4)
System.out.println("stack overflow");
else
{
System.out.println("enter the element to push");
b=Double.parseDouble(bf.readLine());
ob.Push(b);
break;
}
case 2:
ob.Pop();
break;
}
}while(ch!=3);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
Comments
Post a Comment