-
Notifications
You must be signed in to change notification settings - Fork 1
/
priorityqueue.java
64 lines (51 loc) · 1.58 KB
/
priorityqueue.java
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
package classWork;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
public class priorityqueue {
static void priorityqueuee(){
PriorityQueue<Integer> qq = new PriorityQueue<>(6);
qq.add(1);
qq.add(2);
qq.add(3);
qq.add(4);
qq.add(5);
qq.offer(6);
int p = qq.remove();
System.out.println("the poll element is " + p);
int q = qq.peek();
System.out.println("the peek element is " +q);
int w = qq.poll();
System.out.println(w);
}
// sp the hashset is famous for storing only the unique element into the hashset
static void hashsett(){
HashSet<Integer> hh = new HashSet<>(0);
hh.add(1);
hh.add(6);
hh.add(3);
hh.add(4);
hh.add(5);
System.out.println("hashset : " +hh);
hh.add(4);
hh.add(3);
}
// much same like hashset bt it does have properties f the linkedlist so linkedlist and hashset bhai bhai..(●'◡'●)
static void Linkedhashset(){
LinkedHashSet<Integer> lh = new LinkedHashSet<>(0);
lh.add(1);
lh.add(4);
lh.add(2);
lh.add(3);
lh.add(5);
lh.add(7);
System.out.println("LinkedHashset :" +lh);
}
public static void main(String[]args){
Linkedhashset();
priorityqueuee();
hashsett();
}
}