/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package stacks;
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;
}
public void DELETE()
{
for(int i=0;i<queue.length;i++)
{
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 {
public static void main(String[] args) {
Scanner input= new Scanner(System.in);
System.out.println("enter 1 for stack");
System.out.println("enter 2 for queue");
String choice=input.next();
if(choice.equals("1"))
{
Prog prog= new Prog();
prog.Empty();
System.out.println("Enter your stack size");
int size=input.nextInt();
prog.stack(size);
System.out.println("Enter values in statk");
for(int i=0;i<size+1;i++)
{
prog.push(input.nextInt());
}
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();
System.out.println("enter d to delete the element");
if(input.next().equals("d"))
{
queue.DELETE();
}}
else{
System.out.println("wrong entry");
}