Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
95 lines (87 loc) · 1.92 KB

File metadata and controls

95 lines (87 loc) · 1.92 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//implementing queue by array
//deletion takes place from the front
class Queue
{
int front, rear, size;
int length;
int array[];
Queue(int length)
{
this.length = length;
front = this.size=0;
rear= length-1;
array = new int[this.length];
}
//checking if Queue doesn't have more space left.
boolean isfull(Queue q)
{
return(q.size==q.length);
}
//checking if the queue is Empty.
boolean isempty(Queue q)
{
return(q.size==0);
}
//enqueue function to insert the elemnrs in the queue
void enqueue(int element)
{
if(isfull(this))
return;
this.rear = (this.rear + 1)%this.length;
this.array[this.rear] = element;
this.size = this.size + 1;
System.out.println(element+ " enqueued to queue");
}
//dequeue function queue to delete an element
int dequeue()
{
if(isempty(this))
return Integer.MIN_VALUE;
int element = this.array[this.front];
this.front = (this.front+1)%this.length;
this.size = this.size=1;
return element;
}
//getting the front of the queue
int front()
{
if(isempty(this))
{
return Integer.MIN_VALUE;
}
return this.array[this.front];
}
//getting the rear of the queue
int rear()
{
if(isempty(this))
{
return Integer.MIN_VALUE;
}
return this.array[this.rear];
}
}
public class Mainc
{
public static void main(String args[])
{
Queue q = new Queue(500);
q.enqueue(1);
q.enqueue(2);
q.enqueue(3);
q.enqueue(4);
q.enqueue(5);
q.enqueue(6);
q.enqueue(7);
q.enqueue(8);
q.enqueue(9);
System.out.println("## BEFORE ##");
System.out.println( q.front()+ "Front element");
System.out.println("Rear element"+q.rear());
System.out.println("## AFTER ##");
q.dequeue();
q.dequeue();
System.out.println("Front element"+q.front());
System.out.println("Rear element"+q.rear());
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.