@@ -2,8 +2,8 @@ import LinkedList from '../linked-list/LinkedList';
2
2
3
3
export default class Stack {
4
4
constructor ( ) {
5
- // We're going to implement Queue based on LinkedList since this
6
- // structures a quite similar. Compare push/pop operations of the Stack
5
+ // We're going to implement Stack based on LinkedList since these
6
+ // structures are quite similar. Compare push/pop operations of the Stack
7
7
// with append/deleteTail operations of LinkedList.
8
8
this . linkedList = new LinkedList ( ) ;
9
9
}
@@ -12,7 +12,7 @@ export default class Stack {
12
12
* @return {boolean }
13
13
*/
14
14
isEmpty ( ) {
15
- // The queue is empty in case if its linked list don 't have tail.
15
+ // The stack is empty if its linked list doesn 't have a tail.
16
16
return ! this . linkedList . tail ;
17
17
}
18
18
@@ -21,7 +21,7 @@ export default class Stack {
21
21
*/
22
22
peek ( ) {
23
23
if ( this . isEmpty ( ) ) {
24
- // If linked list is empty then there is nothing to peek from.
24
+ // If the linked list is empty then there is nothing to peek from.
25
25
return null ;
26
26
}
27
27
@@ -34,16 +34,16 @@ export default class Stack {
34
34
*/
35
35
push ( value ) {
36
36
// Pushing means to lay the value on top of the stack. Therefore let's just add
37
- // new value at the end of the linked list.
37
+ // the new value at the end of the linked list.
38
38
this . linkedList . append ( value ) ;
39
39
}
40
40
41
41
/**
42
42
* @return {* }
43
43
*/
44
44
pop ( ) {
45
- // Let's try to delete the last node from linked list (the tail).
46
- // If there is no tail in linked list (it is empty) just return null.
45
+ // Let's try to delete the last node (the tail) from the linked list .
46
+ // If there is no tail (the linked list is empty) just return null.
47
47
const removedTail = this . linkedList . deleteTail ( ) ;
48
48
return removedTail ? removedTail . value : null ;
49
49
}
0 commit comments