This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Deletes the item at the top of the Stack | |
this.pop = function () { | |
if (this.isEmpty() === false) { | |
this.count--; | |
var result = this.data[this.count]; | |
delete this.data[this.count]; | |
return result; | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
isEmpty() { | |
return this.top === 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const stack = function() { | |
this.count = 0; | |
this.data = {}; | |
// Puts an element into the Stack | |
this.push = function(element) { | |
this.data[this.count] = element; | |
this.count++; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Step 1: | |
return Stack[top] | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Step 1: | |
if top = -1 | |
print 'Stack is empty' | |
return true | |
else | |
print 'Stack is not empty' | |
return false | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Step 1: | |
if top = max | |
print 'Stack is full' | |
return true | |
else | |
print 'Stack is not full' | |
return false | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Step 1: | |
if Stack is empty | |
print 'Stack is empty' | |
return null | |
Step 2: | |
deleteElement = Stack[top] | |
top = top-- | |
return Stack | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Step 1: | |
if Stack is full | |
print 'Stack is full' | |
return null | |
Step 2: | |
top = top++ | |
Stack[top] = data | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
search(data) { | |
let current = this.root; | |
while (current.data !== data) { | |
if (data < current.data) { | |
current = current.left; | |
} else { | |
current = current.right; | |
} | |
if (current === null) { | |
return null; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
remove(data) { | |
const removeNode = function(node, data) { | |
// Check if the node(parent node) is null or not | |
if (node === null) { | |
return null; | |
} | |
if (data === node.data) { | |
// Check if both left and right node have no child and return null | |
if (node.left === null && node.right === null) { | |
return null; |