Skip to content

[FTRMT2023] Marat Pomeranets #1134

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
134 changes: 54 additions & 80 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,92 +1,66 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>DataStructures | Stacks &amp; Queues</title>
<link
rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
crossorigin="anonymous"
/>
<link rel="stylesheet" href="styles/style.css" />
</head>

<body>
<h1 class="text-center">Data Structures</h1>
<head>
<meta charset="UTF-8" />
<title>DataStructures | Stacks &amp; Queues</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous" />
<link rel="stylesheet" href="styles/style.css" />
</head>

<div class="container" id="container">
<div class="row">
<div class="col-sm-4">
<h2>Stack</h2>
<div class="form-group">
<label for=""></label>
<input
class="form-control"
id="stack-input"
placeholder="Add element to the stack"
/>
</div>
<button
id="add-stack"
type="button"
class="btn btn-primary btn-block"
>
Add to stack
</button>
<button
id="take-stack"
type="button"
class="btn btn-danger btn-block"
>
Remove from stack
</button>
<div class="stack-container" id="stack-container">
<div class="warning-top alert alert-danger"></div>
<ul id="stack-list" class="list-stack"></ul>
<div class="warning-bottom alert alert-danger"></div>
</div>
<body>
<h1 class="text-center">Data Structures</h1>

<div class="container" id="container">
<div class="row">
<div class="col-sm-4">
<h2>Stack</h2>
<div class="form-group">
<label for=""></label>
<input class="form-control" id="stack-input" placeholder="Add element to the stack" />
</div>
<button id="add-stack" type="button" class="btn btn-primary btn-block">
Add to stack
</button>
<button id="take-stack" type="button" class="btn btn-danger btn-block">
Remove from stack
</button>
<div class="stack-container" id="stack-container">
<div class="warning-top alert alert-danger"></div>
<ul id="stack-list" class="list-stack"></ul>
<div class="warning-bottom alert alert-danger"></div>
</div>
<div class="col-sm-1"></div>
</div>
<div class="col-sm-1"></div>

<div class="col-sm-7">
<h2>Queue</h2>
<div class="form-group">
<label for=""></label>
<input
class="form-control queue-input"
id="queue-input"
placeholder="Add element to the queue"
/>
</div>
<button
id="add-queue"
type="button"
class="btn btn-primary btn-block btn-add-queue"
>
Add to queue
</button>
<button
id="take-queue"
type="button"
class="btn btn-danger btn-block btn-take-dequeue"
>
Remove from queue
</button>
<div class="col-sm-7">
<h2>Queue</h2>
<div class="form-group">
<label for=""></label>
<input class="form-control queue-input" id="queue-input" placeholder="Add element to the queue" />
</div>
<button id="add-queue" type="button" class="btn btn-primary btn-block btn-add-queue">
Add to queue
</button>
<button id="take-queue" type="button" class="btn btn-danger btn-block btn-take-dequeue">
Remove from queue
</button>

<div class="stack-container" id="queue-container">
<div class="warning-top alert alert-danger"></div>
<ul id="queue-list" class="list-queue"></ul>
<div class="warning-bottom alert alert-danger"></div>
</div>
<div class="stack-container" id="queue-container">
<div class="warning-top alert alert-danger"></div>
<ul id="queue-list" class="list-queue"></ul>
<div class="warning-bottom alert alert-danger"></div>
</div>
</div>
</div>
</div>

<script src="src/stack/stack-data-structure.js"></script>
<script src="src/queue/queue-data-structure.js"></script>

<script src="src/stack/stack-data-structure.js"></script>
<script src="src/queue/queue-data-structure.js"></script>
<script src="src/stack/stack-dom.js"></script>
<script src="src/queue/queue-dom.js"></script>
</body>

<script src="src/stack/stack-dom.js"></script>
<script src="src/queue/queue-dom.js"></script>
</body>
</html>
</html>
16 changes: 15 additions & 1 deletion src/queue/queue-data-structure.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,37 @@ 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()) {
return this.queueControl.shift()
} 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
30 changes: 30 additions & 0 deletions src/queue/queue-dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,65 @@ 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.innerText = '&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 {
queue.enqueue(queueInput.value);
clearQueueInput();
generateListQueue();
// ... your code goes here
} catch (error) {
// there was an overflow error, handle it
generateWarningQueue('overflow')
}
};

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

Expand Down
16 changes: 15 additions & 1 deletion src/stack/stack-data-structure.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,37 @@ 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 {
throw new Error('STACK_OVERFLOW');
}
}

pop() {
// ... your code goes here
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.
Expand Down