File tree Expand file tree Collapse file tree 2 files changed +30
-15
lines changed Expand file tree Collapse file tree 2 files changed +30
-15
lines changed Original file line number Diff line number Diff line change
1
+ const Queue = require ( '../../src/js/data-structures/queue' )
2
+
3
+ const queue = new Queue ( )
4
+
5
+ queue . enqueue ( 'Carlos' )
6
+ queue . enqueue ( 'joana' )
7
+ queue . enqueue ( 'Maria' )
8
+
9
+ console . log ( 'Peek' , queue . peek ( ) )
10
+ queue . dequeue ( )
11
+ console . log ( 'Peek' , queue . peek ( ) )
12
+ console . log ( 'Size' , queue . size ( ) )
13
+ queue . clear ( )
14
+ console . log ( 'Size' , queue . size ( ) )
15
+ console . log ( 'IsEmpty?' , queue . isEmpty ( ) )
Original file line number Diff line number Diff line change 1
1
class Queue {
2
2
constructor ( ) {
3
- this . count = 0
4
- this . lowestCount = 0
5
- this . items = { }
3
+ this . _count = 0
4
+ this . _lowestCount = 0
5
+ this . _items = { }
6
6
}
7
7
8
8
/**
9
9
* Adiciona elemento na fila
10
10
* @param {* } element
11
11
*/
12
12
enqueue ( element ) {
13
- this . items [ this . count ] = element
14
- this . count ++
13
+ this . _items [ this . _count ] = element
14
+ this . _count ++
15
15
}
16
16
17
17
/**
@@ -20,8 +20,8 @@ class Queue {
20
20
*/
21
21
dequeue ( ) {
22
22
if ( this . isEmpty ( ) ) return undefined
23
- const result = this . items [ this . lowestCount ]
24
- this . lowestCount ++
23
+ const result = this . _items [ this . _lowestCount ]
24
+ this . _lowestCount ++
25
25
return result
26
26
}
27
27
@@ -30,14 +30,14 @@ class Queue {
30
30
*/
31
31
peek ( ) {
32
32
if ( this . isEmpty ( ) ) return undefined
33
- return this . items [ this . lowestCount ]
33
+ return this . _items [ this . _lowestCount ]
34
34
}
35
35
36
36
/**
37
37
* @returns {int } retorna tamanho da fila
38
38
*/
39
39
size ( ) {
40
- return this . count - this . lowestCount
40
+ return this . _count - this . _lowestCount
41
41
}
42
42
43
43
/**
@@ -52,16 +52,16 @@ class Queue {
52
52
* Limpa a fila
53
53
*/
54
54
clear ( ) {
55
- this . items = { }
56
- this . count = 0
57
- this . lowestCount = 0
55
+ this . _items = { }
56
+ this . _count = 0
57
+ this . _lowestCount = 0
58
58
}
59
59
60
60
toString ( ) {
61
61
if ( this . isEmpty ( ) ) return ''
62
- let objString = `${ this . items [ this . lowestCount ] } `
63
- for ( let i = this . lowestCount + 1 ; i < this . count ( ) ; i ++ ) {
64
- objString += `${ objString } , ${ this . items [ i ] } `
62
+ let objString = `${ this . _items [ this . _lowestCount ] } `
63
+ for ( let i = this . _lowestCount + 1 ; i < this . _count ( ) ; i ++ ) {
64
+ objString += `${ objString } , ${ this . _items [ i ] } `
65
65
}
66
66
67
67
return objString
You can’t perform that action at this time.
0 commit comments