Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions src/queue/queue-data-structure.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,44 @@ class Queue {
}

canEnqueue() {
// ... your code goes here
if (this.queueControl.length < this.MAX_SIZE) {
return true
} else {
return false
}

}

isEmpty() {
// ... your code goes here
if (this.queueControl.length === 0) {
return true
} else {
return false
}
}

enqueue(item) {
// ... your code goes here
if (this.canEnqueue() === true) {
this.queueControl.push(item)
return this.queueControl
} else {
throw new Error('QUEUE_OVERFLOW');
}
}

dequeue() {
// ... your code goes here
if (this.isEmpty() === false) {
const removed = this.queueControl.shift()
return removed
} else {
throw new Error('QUEUE_UNDERFLOW');
}

}

display() {
// ... your code goes here
}
return this.queueControl
}
}

// This is required to enable the automated tests, please ignore it.
Expand Down
43 changes: 34 additions & 9 deletions src/queue/queue-dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,63 @@ const dequeue = document.querySelector('.btn-take-dequeue');
const queue = new Queue();

const clearQueueInput = () => {
// ... your code goes here
queueInput.value = '';
};

const generateListQueue = () => {
// ... your code goes here
warningTopQueue.style.display = 'none';
warningBottomQueue.style.display = 'none';
queueUL.innerHTML = '';
let length = queue.display().length;
let size = queue.MAX_SIZE - length;

queue.display().forEach(item => {
let li = document.createElement('li');
li.className = 'active';
li.innerText = item;
queueUL.appendChild(li);
});

for (let i = 0; i < size; i++) {
let li = document.createElement('li');
li.className = 'inactive';
li.innerHTML = '&nbsp;';
queueUL.appendChild(li);
}
};


generateListQueue();


const generateWarningQueue = (type) => {
if (type === 'underflow') {
// ... your code goes here
warningBottomQueue.style.display = 'block';
warningBottomQueue.innerText = type;
} else if (type === 'overflow') {
// ... your code goes here
warningTopQueue.style.display = 'block';
warningTopQueue.innerText = type;
}
};

const addToQueue = () => {
try {
// ... your code goes here
queue.enqueue(queueInput.value)
clearQueueInput();
generateListQueue()
} catch (error) {
// there was an overflow error, handle it
generateWarningQueue('overflow∫')
}
};

const removeFromQueue = () => {
try {
// ... your code goes here
queue.dequeue()
generateListQueue()
} catch (error) {
// there was an underflow error, handle it
generateWarningQueue('underflow')
}
};

addQueue.addEventListener('click', addToQueue);
dequeue.addEventListener('click', removeFromQueue);
dequeue.addEventListener('click', removeFromQueue);
31 changes: 25 additions & 6 deletions src/stack/stack-data-structure.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,43 @@ class Stack {
}

canPush() {
// ... your code goes here
if (this.stackControl.length < this.MAX_SIZE) {
return true
} else {
return false
}
}

isEmpty() {
// ... your code goes here
if (this.stackControl.length === 0) {
return true
} else {
return false
}
}

push(item) {
// ... your code goes here
if (this.canPush() === true) {
this.stackControl.push(item)
return this.stackControl
} else {
throw new Error('STACK_OVERFLOW');
}

}

pop() {
// ... your code goes here
if (this.isEmpty() === false) {
const arr = this.stackControl.pop()
return arr
} else {
throw new Error('STACK_UNDERFLOW');
}
}

display() {
// ... your code goes here
}
return this.stackControl
}
}

// This is required to enable the automated tests, please ignore it.
Expand Down