MCPcopy Create free account
hub / github.com/PrajaktaSathe/Java / Circular_Queue

Class Circular_Queue

Programs/Circular_Queue.java:1–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1public class Circular_Queue {
2
3 static class Node {
4 int value;
5 Node link;
6 }
7
8 static class CircularQueue {Node first, last;}
9
10 static void Insert(CircularQueue cq, int value) {
11 Node n = new Node();
12 n.value = value;
13
14 if (cq.first == null) {
15 cq.first = n;
16 } else { cq.last .link = n; }
17
18 cq.last = n;
19 cq.last.link = cq.first;
20 }
21
22 static int Delete(CircularQueue cq) {
23 if (cq.first == null) {
24 System.out.printf ("Circular Queue is empty");
25 return Integer.MIN_VALUE;
26 }
27
28 int value;
29
30 if (cq.first == cq.last) {
31 value = cq.first.value;
32 cq.first = null;
33 cq.last = null;
34 } else {
35 Node n = cq.first;
36 value = n.value;
37 cq.first = cq.first.link;
38 cq.last.link = cq.first;
39 }
40
41 return value ;
42 }
43
44 static void displayCircularQueue( CircularQueue cq) {
45 Node n = cq.first;
46 System.out.printf("\nElements in Circular Queue are: ");
47 while (n.link != cq.first) {
48 System.out.printf("%d ", n.value);
49 n = n.link;
50 }
51 System.out.printf("%d", n.value);
52 }
53
54 public static void main(String[] args) {
55
56 CircularQueue cq = new CircularQueue();
57 cq.first = cq.last = null;
58
59 System.out.println("Inserting value = 69");
60 Insert(cq, 69);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected