mirror of
https://github.com/trekhleb/javascript-algorithms.git
synced 2025-07-07 18:10:24 +08:00
Improve JSDocs in Stack.js (#203)
The functions' comments were copied from Queue.js, but some words were not replaced. I also made some changes to the wording for clarification.
This commit is contained in:

committed by
Oleksii Trekhleb

parent
6f27113993
commit
1a62078f26
@ -2,8 +2,8 @@ import LinkedList from '../linked-list/LinkedList';
|
|||||||
|
|
||||||
export default class Stack {
|
export default class Stack {
|
||||||
constructor() {
|
constructor() {
|
||||||
// We're going to implement Queue based on LinkedList since this
|
// We're going to implement Stack based on LinkedList since these
|
||||||
// structures a quite similar. Compare push/pop operations of the Stack
|
// structures are quite similar. Compare push/pop operations of the Stack
|
||||||
// with append/deleteTail operations of LinkedList.
|
// with append/deleteTail operations of LinkedList.
|
||||||
this.linkedList = new LinkedList();
|
this.linkedList = new LinkedList();
|
||||||
}
|
}
|
||||||
@ -12,7 +12,7 @@ export default class Stack {
|
|||||||
* @return {boolean}
|
* @return {boolean}
|
||||||
*/
|
*/
|
||||||
isEmpty() {
|
isEmpty() {
|
||||||
// The queue is empty in case if its linked list don't have tail.
|
// The stack is empty if its linked list doesn't have a tail.
|
||||||
return !this.linkedList.tail;
|
return !this.linkedList.tail;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ export default class Stack {
|
|||||||
*/
|
*/
|
||||||
peek() {
|
peek() {
|
||||||
if (this.isEmpty()) {
|
if (this.isEmpty()) {
|
||||||
// If linked list is empty then there is nothing to peek from.
|
// If the linked list is empty then there is nothing to peek from.
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ export default class Stack {
|
|||||||
*/
|
*/
|
||||||
push(value) {
|
push(value) {
|
||||||
// Pushing means to lay the value on top of the stack. Therefore let's just add
|
// Pushing means to lay the value on top of the stack. Therefore let's just add
|
||||||
// new value at the end of the linked list.
|
// the new value at the end of the linked list.
|
||||||
this.linkedList.append(value);
|
this.linkedList.append(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,8 +42,8 @@ export default class Stack {
|
|||||||
* @return {*}
|
* @return {*}
|
||||||
*/
|
*/
|
||||||
pop() {
|
pop() {
|
||||||
// Let's try to delete the last node from linked list (the tail).
|
// Let's try to delete the last node (the tail) from the linked list.
|
||||||
// If there is no tail in linked list (it is empty) just return null.
|
// If there is no tail (the linked list is empty) just return null.
|
||||||
const removedTail = this.linkedList.deleteTail();
|
const removedTail = this.linkedList.deleteTail();
|
||||||
return removedTail ? removedTail.value : null;
|
return removedTail ? removedTail.value : null;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user