File tree 2 files changed +32
-2
lines changed
2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change
1
+ class Queue {
2
+ constructor ( ) {
3
+ this . items = [ ] ;
4
+ }
5
+
6
+ enqueue ( item ) {
7
+ this . items . push ( item ) ;
8
+ }
9
+
10
+ dequeue ( ) {
11
+ return this . items . shift ( ) ;
12
+ }
13
+
14
+ size ( ) {
15
+ return this . items . length ;
16
+ }
17
+
18
+ peek ( ) {
19
+ return this . items [ 0 ] ;
20
+ }
21
+ }
22
+
23
+ const queue = new Queue ( ) ;
24
+ queue . enqueue ( 5 ) ; // Queue state: [5]
25
+ queue . enqueue ( 10 ) ; // Queue state: [5, 10]
26
+ queue . enqueue ( 13 ) ; // Queue state: [5, 10, 13]
27
+ console . log ( queue . peek ( ) ) ; // Output: 5
28
+ console . log ( queue . dequeue ( ) ) ; // Output: 5, Queue State: [10, 13]
29
+ console . log ( queue . peek ( ) ) ; // Output: 10
30
+ console . log ( queue . size ( ) ) ; // Output: 2
Original file line number Diff line number Diff line change @@ -5,8 +5,8 @@ Code accompanying my illustrated Data structures [video series on YouTube](https
5
5
* [ What are Data Structures?] ( https://www.youtube.com/watch?v=9rhT3P1MDHk ) — [ ** Watch Video** ] ( https://www.youtube.com/watch?v=9rhT3P1MDHk )
6
6
* [ Array] ( ./array.js ) — [ ** Watch Video** ] ( https://www.youtube.com/watch?v=QJNwK2uJyGs )
7
7
* [ Linked List] ( ./linked-list.js ) — [ ** Watch Video** ] ( https://www.youtube.com/watch?v=odW9FU8jPRQ )
8
- * [ Stack] ( ./stack.js ) — [ Soon on YouTube ] ( https://www.youtube.com/theroadmap?sub_confirmation=1 )
9
- * Queue — [ Soon on YouTube] ( https://www.youtube.com/theroadmap?sub_confirmation=1 )
8
+ * [ Stack] ( ./stack.js ) — [ ** Watch Video ** ] ( https://www.youtube.com/watch?v=I5lq6sCuABE )
9
+ * [ Queue] ( ./queue.js ) — [ Soon on YouTube] ( https://www.youtube.com/theroadmap?sub_confirmation=1 )
10
10
* Heap — [ Soon on YouTube] ( https://www.youtube.com/theroadmap?sub_confirmation=1 )
11
11
* Hash Table — [ Soon on YouTube] ( https://www.youtube.com/theroadmap?sub_confirmation=1 )
12
12
* Tree — [ Soon on YouTube] ( https://www.youtube.com/theroadmap?sub_confirmation=1 )
You can’t perform that action at this time.
0 commit comments