import java.io.*;
class queue
{
public static void main()throws IOException
{
BufferedReader br=new BufferedReader(
new InputStreamReader(System.in));
int ar[]=new int[5];
int rear,front,ch;
rear=front=-1;
do
{
System.out.println("1.Insert element");
System.out.println("2.Delete element");
System.out.println("3.Display element");
System.out.println("4.Exit");
System.out.print("Enter your choice :-");
ch=Integer.parseInt(br.readLine());
switch(ch)
{
case 1:
if((rear+1)>4)
System.out.println("Stack overflow...");
else
{
System.out.print("Enter element :-");
ar[++rear]=Integer.parseInt(br.readLine());
}
if(front == -1)
front=0;
break;
case 2:
if(front == -1)
System.out.println("Stack underflow....");
else
System.out.println("Poped element :-"+ar[front++]);
if(front>rear)
front=rear=-1;
break;
case 3:
if(front == -1)
System.out.println("Stack underflow....");
else
{
for(int i=front;i<=rear;i++)
{
System.out.print(ar[i]+"\t");
}
System.out.println();
}
break;
case 4:
System.out.println("Program end....");
break;
default:
System.out.println("Invalid choice enter....");
}
}while(ch != 4);
}
}
No comments:
Post a Comment