forked from jvm-coder/Java_Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedlistdeque.java
More file actions
32 lines (31 loc) · 824 Bytes
/
Linkedlistdeque.java
File metadata and controls
32 lines (31 loc) · 824 Bytes
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
// deque implementation using LinkedList
import java.util.*;
public class Linkedlistdeque
{
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
Deque<Integer> deque = new LinkedList<Integer>();
for(int i=0;i<6;i++){
deque.add(sc.nextInt());
}
System.out.println(deque);
// add at the last
deque.add(344);
// add at the first
deque.addFirst(77);
// add at the last
deque.addLast(89);
// add at the first
deque.push(56);
// add at the last
deque.offer(90);
// add at the first
deque.offerFirst(800);
System.out.println(deque);
// remove First
deque.removeFirst();
// remove Last
deque.removeLast();
System.out.println(deque);
}
}