Вы находитесь на странице: 1из 2

/*

* 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 queue;

import java.util.Scanner;

/**
*
* @author Anam
*/
public class Queue {

int front = -1;


int rear = -1;
int maxsize=6;
int queue[]=new int [maxsize];
void insert(int item)
{
if(rear==maxsize-1)
{
System.out.println("queue overflow");
return;

}
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

Queue a = new Queue();

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");
}
}

Вам также может понравиться