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
23 changes: 16 additions & 7 deletions src/queue/queue-data-structure.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,34 @@ class Queue {
}

canEnqueue() {
// ... your code goes here
return this.queueControl.length < this.MAX_SIZE;
}

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

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

dequeue() {
// ... your code goes here
if (this.isEmpty()) {
throw new Error("QUEUE_UNDERFLOW")
} else {
const queueElim = this.queueControl[0]
this.queueControl.shift()
return queueElim;
}

}

display() {
// ... your code goes here
}
return [...this.queueControl]; //devuelve la copia
}
}

// This is required to enable the automated tests, please ignore it.
if (typeof module !== 'undefined') module.exports = Queue;
48 changes: 40 additions & 8 deletions src/queue/queue-dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,68 @@ 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

warningBottomQueue.style.display = 'none';
warningTopQueue.style.display = 'none';
queueUL.innerHTML = '';

//calculo longitud del array de elementos (display),
//calculo el espacio que queda sin ocupar para dejarlo vacio

let length = queue.display().length
let size = queue.MAX_SIZE - length

for (let i = 0; i < length; i++) {
let queueLI = document.createElement("li");
queueLI.className = 'active';
queueLI.innerText = queue.display()[i];
queueUL.appendChild(queueLI);
};
for (let i = 0; i < size; i++) {
let queueLI = document.createElement("li");
queueLI.className = 'inactive'
queueLI.innerHTML = '&nbsp;';
queueUL.appendChild(queueLI)
};
}

generateListQueue();

const generateWarningQueue = (type) => {
if (type === 'underflow') {
// ... your code goes here
warningBottomQueue.style.display = 'block'
warningBottomQueue.innerHTML = "underflow"

} else if (type === 'overflow') {
// ... your code goes here
warningTopQueue.style.display = 'block'
warningTopQueue.innerHTML = "overflow"
}
};

const addToQueue = () => {
try {
// ... your code goes here
queue.enqueue(queueInput.value);
generateListQueue()
clearQueueInput()

} catch (error) {
// there was an overflow error, handle it
console.error("QUEUE_OVERFLOW")
generateWarningQueue('overflow')
}
};

const removeFromQueue = () => {
try {
// ... your code goes here
queue.dequeue()
generateListQueue()

} catch (error) {
// there was an underflow error, handle it
console.error("QUEUE_UNDERFLOW")
generateWarningQueue("underflow")
}
};

Expand Down
24 changes: 18 additions & 6 deletions src/stack/stack-data-structure.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,36 @@ class Stack {
}

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


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

push(item) {
// ... your code goes here
if (this.canPush()) {
this.stackControl.push(item)
return this.stackControl;
} else { return 'Stack Overflow'}

}

pop() {
// ... your code goes here
if (this.isEmpty()) {
return 'Stack Underflow';
} else {
const stackElim = this.stackControl[this.stackControl.length - 1]
this.stackControl.pop()
return stackElim;
}
}


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

// This is required to enable the automated tests, please ignore it.
Expand Down
2 changes: 1 addition & 1 deletion src/stack/stack-dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const warningBottomStack = document.querySelector('#stack-container .warning-bot
const addStackBtn = document.getElementById('add-stack');
const takeStackBtn = document.getElementById('take-stack');

const newStack = new Stack();
const newStack = new Stack(); //definimos la clase

const clearStackInput = () => {
stackInput.value = '';
Expand Down