File tree 1 file changed +33
-0
lines changed
1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ # CHEAT SHEET
2
+
3
+ ## Stacks & Queues / Стекове и Опашки
4
+ ``` java
5
+ ### Stack - LIFO - First in First Out
6
+ Deque<Integer > stack = new ArrayDeque<> ();
7
+ push(element) - insert element on the top of the stack
8
+ pop() - remove topmost element
9
+ peek() - get topmost element
10
+
11
+ ### Queue - FIFO - First in First out
12
+ Deque<Integer > queue = new ArrayDeque<> ();
13
+ offer(element) - add element at the start of the Queue
14
+ poll() - remove first element of the Queue
15
+ peek() - get first element of the Queue
16
+
17
+ ### PriorityQueue
18
+ PriorityQueue<String > fruits = new PriorityQueue<> ();
19
+ - нарежда ги по азбучен ред или по големина
20
+
21
+ while (! queue. isEmpty()){
22
+ Integer element = queue. poll();
23
+ System . out. println(element);
24
+ } - принтира всичките елементи (важи и за опашките)
25
+
26
+ ******** important *********
27
+ add() – throws exception if queue is full
28
+ offer()– returns false if a queue is full
29
+ remove()- throws exception if queue is empty
30
+ poll()- returns null if queue is empty
31
+
32
+ ```
33
+ ## Multidimensional Arrays / Многомерни масиви - матрици
You can’t perform that action at this time.
0 commit comments