Skip to content
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

stacks and queues done #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

stacks and queues done #18

wants to merge 1 commit into from

Conversation

dnsrocha
Copy link

Stacks and Queues

Thanks for doing some brain yoga. You are now submitting this assignment!

Comprehension Questions

Question Answer
What is an ADT? Abstract Data Type - A type of object which is described by the methods it has and how they perform.
Describe a Stack A Stack is a data structure which stores a list of data and only provides access in a Last-In-First-Out (LIFO) order.
What are the 5 methods in Stack and what does each do? New (initializes the stack), push (adds an item to the stack), pop (removes item from stack), empty (checks if stack is empty), to_s (converts stack to string)
Describe a Queue A Queue is a data structure which stores a list of data and only provides access in a First-In-First-Out (FIFO) order.
What are the 5 methods in Queue and what does each do? New (initializes the queue), enqueue (adds an item to the queue), dequeue (removes an item from the queue and provides ice cream), empty (checks if a queue is empty), to_s (converts a queue to string)
What is the difference between implementing something and using something? Implementing is writing the code behind a problem statement or objective, while using is just running it.

OPTIONAL JobSimulation

Question Answer
Did you include a sample run of your code as a comment?

Copy link

@CheezItMan CheezItMan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done Denise, you hit the learning goals here. Nice work!

@store = Array.new(20)
@start = 0
# @end = 0
@size = 0
end

def enqueue(element)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

if size < 20
@store[(@start + @size) % 20] = element
@size += 1
end
end

def dequeue

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

raise NotImplementedError, "Not yet implemented"
if @size != 0
element = @store[@start]
@start = (@start + 1 ) % 20

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid hardcoding the 20

Suggested change
@start = (@start + 1 ) % 20
@start = (@start + 1 ) % @store.length

@start = (@start + 1 ) % 20
@size -= 1
return element
end
end

def front

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

end

def front
raise NotImplementedError, "Not yet implemented"
return @store[@start]
end

def size

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

end

def size
raise NotImplementedError, "Not yet implemented"
return @size
end

def empty?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

end

def empty?
raise NotImplementedError, "Not yet implemented"
return @size == 0
end

def to_s

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -1,19 +1,26 @@
class Stack

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants