Академический Документы
Профессиональный Документы
Культура Документы
import java.util.Scanner;
/**
*
* @author Anam
*/
public class Queue {
}
if(front==-1)
{
front = 0;
}
rear=rear+1;
queue[rear]=item;
}
void del()
{
if(front == -1||front > rear)
{
System.out.println("queue underflow");
return;
}
else
{
System.out.println("element deleted from the queue =
"+queue[front]);
front=front+1;
}
}
void display()
{
if(front == -1)
{
System.out.println("queue is empty");
}
else
{
for(int i=front;i<=rear;i++)
{
System.out.println("element = "+queue[i]);
}
}
}
public static void main(String[] args) {
// TODO code application logic here
int i=1;
while(i==1)
{
System.out.println("Enter 1 for insertionn operation");
System.out.println("Enter 2 for deletion operation");
System.out.println("Enter 3 for display operation");
System.out.println("Enter your operation");
int op,item;
Scanner sc = new Scanner(System.in);
op=sc.nextInt();
switch(op)
{
case 1:
{
System.out.println("enter item you want to insert in stack");
item=sc.nextInt();
a.insert(item);
break;
}
case 2:
{
a.del();
break;
}
case 3:
{
a.display();
break;
}
default:
System.out.println("invalid option");
}
}