Skip to content

Commit f71e311

Browse files
Queue
1 parent 0f02e2a commit f71e311

3 files changed

Lines changed: 45 additions & 0 deletions

File tree

1.15 KB
Binary file not shown.
1.15 KB
Binary file not shown.

src/TheQueue.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import java.util.LinkedList;
2+
import java.util.Queue;
3+
4+
public class TheQueue {
5+
6+
public static void main(String[] args) {
7+
Queue<Person> market = new LinkedList<>();
8+
market.add(new Person("Raheem", 21));
9+
market.add(new Person("Nargeeza", 21));
10+
market.offer(new Person("Islam", 11));
11+
12+
System.out.println(market.size());
13+
System.out.println(market.peek());
14+
System.out.println(market.poll());
15+
System.out.println(market.size());
16+
System.out.println(market.remove());
17+
System.out.println(market.peek());
18+
}
19+
20+
private static class Person {
21+
private final String name;
22+
private final int age;
23+
24+
public Person(String name, int age) {
25+
this.name = name;
26+
this.age = age;
27+
}
28+
29+
public String getName() {
30+
return name;
31+
}
32+
33+
public int getAge() {
34+
return age;
35+
}
36+
37+
@Override
38+
public String toString() {
39+
return "Person{" +
40+
"name='" + name + '\'' +
41+
", age=" + age +
42+
'}';
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)