You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
915 B
JavaScript
68 lines
915 B
JavaScript
10 months ago
|
let collection = [];
|
||
|
|
||
|
function print(){
|
||
|
return collection;
|
||
|
}
|
||
|
|
||
|
|
||
|
function enqueue(){
|
||
|
collection[collection.length]
|
||
|
return collection;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
function dequeue(num) {
|
||
|
for (let i = 0; i < num; i++) {
|
||
|
for (let k = 0; k < collection.length - 1; k++) {
|
||
|
collection[k] = collection[k + 1];
|
||
|
}
|
||
|
collection.length--;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
dequeue(1);
|
||
|
|
||
|
|
||
|
|
||
|
function front() {
|
||
|
for(let i = 0; i < collection.length; i++) {
|
||
|
console.log(collection[i]);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
front();
|
||
|
|
||
|
|
||
|
let totalElements = 0;
|
||
|
|
||
|
function size(){
|
||
|
collection[collection.length]
|
||
|
return collection;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
function isEmpty() {
|
||
|
return collection.length === 0;
|
||
|
}
|
||
|
|
||
|
console.log(isEmpty()); // Output: false
|
||
|
|
||
|
collection = []; // Reset the collection array to an empty state
|
||
|
|
||
|
console.log(isEmpty()); // Output: true
|
||
|
|
||
|
|
||
|
// Write the queue functions below.
|
||
|
|
||
|
module.exports = {
|
||
|
collection,
|
||
|
|
||
|
print,
|
||
|
enqueue,
|
||
|
dequeue,
|
||
|
front,
|
||
|
size,
|
||
|
isEmpty
|
||
|
};
|