Skip to content

BERFTAUG2023 - Madhushree Boyle #1140

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 4 commits 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
6 changes: 6 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,30 @@ <h2>Stack</h2>
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>

<div class="col-sm-1"></div>

<div class="col-sm-7">
Expand All @@ -59,13 +63,15 @@ <h2>Queue</h2>
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"
Expand Down
12 changes: 12 additions & 0 deletions src/queue/queue-data-structure.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,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() === false){
throw new Error('QUEUE_OVERFLOW')
}
this.queueControl.push(item);
return this.queueControl;
}

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

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

Expand Down
20 changes: 19 additions & 1 deletion src/stack/stack-data-structure.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,40 @@ class Stack {

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

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

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) {
return this.stackControl.pop();
} else {
throw new Error("STACK_UNDERFLOW");
}
}

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

Expand Down