Skip to content

#02 should be ok?[BER-WDPT-2024] Yujiro Akihiro #1144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
33 changes: 21 additions & 12 deletions src/queue/queue-data-structure.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,38 @@
class Queue {
class Stack {
constructor() {
this.queueControl = [];
this.stackControl = [];
this.MAX_SIZE = 10;
}

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

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

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

dequeue() {
// ... your code goes here
pop() {
if (!this.isEmpty()) {
return this.stackControl.pop();
} 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.
if (typeof module !== 'undefined') module.exports = Queue;
if (typeof module !== 'undefined') module.exports = Stack;
67 changes: 29 additions & 38 deletions src/queue/queue-dom.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,38 @@
const queueUL = document.querySelector('.list-queue');
const queueInput = document.querySelector('.queue-input');
const warningTopQueue = document.querySelector('#queue-container .warning-top');
const warningBottomQueue = document.querySelector(
'#queue-container .warning-bottom'
);
const addQueue = document.querySelector('.btn-add-queue');
const dequeue = document.querySelector('.btn-take-dequeue');

const queue = new Queue();

const clearQueueInput = () => {
// ... your code goes here
};
class Queue {
constructor() {
this.queueControl = [];
this.MAX_SIZE = 10;
}

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

generateListQueue();
isEmpty() {
return this.queueControl.length === 0;
}

const generateWarningQueue = (type) => {
if (type === 'underflow') {
// ... your code goes here
} else if (type === 'overflow') {
// ... your code goes here
enqueue(item) {
if (this.canEnqueue()) {
this.queueControl.push(item);
return this.queueControl;
} else {
throw new Error('QUEUE_OVERFLOW');
}
}
};

const addToQueue = () => {
try {
// ... your code goes here
} catch (error) {
// there was an overflow error, handle it
dequeue() {
if (!this.isEmpty()) {
return this.queueControl.shift();
} else {
throw new Error('QUEUE_UNDERFLOW');
}
}
};

const removeFromQueue = () => {
try {
// ... your code goes here
} catch (error) {
// there was an underflow error, handle it
display() {
return this.queueControl;
}
};
}

addQueue.addEventListener('click', addToQueue);
dequeue.addEventListener('click', removeFromQueue);
// This is required to enable the automated tests, please ignore it.
if (typeof module !== 'undefined') module.exports = Queue;