-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedList
More file actions
30 lines (21 loc) · 791 Bytes
/
LinkedList
File metadata and controls
30 lines (21 loc) · 791 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
import java.util.LinkedList;
public class main {
public static void main(String[] args) {
LinkedList<Integer> list=new LinkedList<>();
list.push(1);
list.push(3);
list.push(4);
list.push(7);
list.push(2);
list.pop();//removes the head
list.add(4,2);//adds an element at an index
list.peekFirst();list.peek();//both peeks at the head
list.peekLast();//peeks at the tail
list.addFirst(10);list.removeFirst();//add and removing the head
list.addLast(10);list.removeLast();//add and removing the tail
// list.offer(4);
// list.offer(7);
// list.offer(2);
// list.poll(); linkedList can be mimicked as a Stack or Queue
}
}