Skip to content

Commit 4e3ae65

Browse files
authored
Merge pull request #54 from LuizGuerra/master
Added methods to stack
2 parents 467b414 + 7edc54d commit 4e3ae65

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

data-structures/stack.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/**
2-
* @author Rashik Ansar
2+
* @author Rashik Ansar and Luiz Guerra
3+
*
34
*
45
* Implemtaion of Stack data structure
56
* Stack follows LIFO (Last In First Out) priniciple
@@ -62,6 +63,42 @@ class Stack {
6263
}
6364
return this.first.data;
6465
}
66+
67+
/**
68+
* @returns size of the Stack
69+
*/
70+
size() {
71+
return this.size;
72+
}
73+
74+
/**
75+
* @returns if Stack is empty
76+
*/
77+
isEmpty() {
78+
return this.size == 0;
79+
}
80+
81+
/**
82+
* clears the Stack
83+
*/
84+
clear() {
85+
this.first = null;
86+
this.last = null;
87+
this.size = 0;
88+
}
89+
90+
/**
91+
* @returns the Stack
92+
*/
93+
toString() {
94+
let str = "";
95+
let aux = this.first;
96+
for (let i = 0; i < this.count; i++)
97+
str += aux.element + " ";
98+
aux = aux.next;
99+
return str;
100+
}
101+
65102
}
66103

67104
class Node {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy