Skip to content

Instantly share code, notes, and snippets.

View Vectormike's full-sized avatar
🏠
Working from home

Victor Jonah Vectormike

🏠
Working from home
View GitHub Profile
// 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;
}
};
isEmpty() {
return this.top === 0;
}
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++;
}
}
Step 1:
return Stack[top]
end
Step 1:
if top = -1
print 'Stack is empty'
return true
else
print 'Stack is not empty'
return false
end
Step 1:
if top = max
print 'Stack is full'
return true
else
print 'Stack is not full'
return false
end
Step 1:
if Stack is empty
print 'Stack is empty'
return null
Step 2:
deleteElement = Stack[top]
top = top--
return Stack
end
Step 1:
if Stack is full
print 'Stack is full'
return null
Step 2:
top = top++
Stack[top] = data
end
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;
@Vectormike
Vectormike / remove.js
Last active September 15, 2021 19:40
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;