Stack and Queue
Stack and Queue
import java.util.Scanner;
class Prog
{
int size;
int top;
int arr[];
public void stack(int size_of_stack)
{
size=size_of_stack;
arr=new int[size];
}
public boolean Empty()
{
if(top==0)
{
return true;
}
else
{
return false;
}
}
public void push(int val)
{
if(top<size){
arr[top]=val;
top++;
}
else
{
System.out.print(" stack overflow \n");}
}
public int pop()
{
if(!this.Empty())
{
int temp=this.peek();
arr[top-1]=0;
top--;
return temp;
}
else
{return 0;}
}
public int peek()
{
if(top>0)
{
return arr[top-1];
}
else
{return 0;}
}
}
class Queue{
int queue[]= new int[5];
int size,front,rear;
public void INSERT(int data)
{
queue[rear]=data;
rear=rear+1;
size=size+1;
}
queue[i]=0;
System.out.println(""+queue[i]);
}
}
public void Show()
{
System.out.println("Elements");
for(int i=0;i<size;i++)
{
System.out.println(" "+queue[i]);
}
}
}
public class STACKs {
}
System.out.println("enter 3 to pops the values");
if(input.next().equals("3"))
{
System.out.println("pope values are");
for(int i=0;i<size;i++)
System.out.print(" "+prog.pop());
}
}
else
{}
prog.peek();
System.out.println(" \n");
}
else if(choice.equals("2")){
System.out.println("the size of queue already created ");
Queue queue=new Queue();
System.out.println("entr the elements in queue");
for(int i=0;i<5;i++)
{
queue.INSERT(input.nextInt());
queue.Show();
queue.DELETE();
}}
else{
System.out.println("wrong entry");
}