Skip to content

Time - Denisse#28

Open
denisseai wants to merge 4 commits intoAda-C13:masterfrom
denisseai:master
Open

Time - Denisse#28
denisseai wants to merge 4 commits intoAda-C13:masterfrom
denisseai:master

Conversation

@denisseai
Copy link
Copy Markdown

Stacks and Queues

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

Comprehension Questions

Question Answer
What is an ADT? An Abstract Data Type is any data type that can be implemented any way, as long as it can perform the operations in its type description.
Describe a Stack It is a type of ADT that uses LIFO
What are the 5 methods in Stack and what does each do? push: adds an element to the stack, pop: removes the last item from the stack, empty : checks whether the stack is empty, to_s: returns a string of the array, initialize: initializes.
Describe a Queue It is a type of ADT that uses FIFO
What are the 5 methods in Queue and what does each do? Enqueue: adds an item to the queue, dequeue: removes the first item from the queue, empty: checks whether the queue is empty, front: returns the value at the front of the queue, size: returns the length of the queue, to_s: returns a string of the array without the nils.
What is the difference between implementing something and using something? "Implementing something" is initializing a class, setting up a data structure and its methods. "Using something" is calling the implementation and running the methods.

OPTIONAL JobSimulation

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

Copy link
Copy Markdown

@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.

Overall nice work Denisse, you hit the main learning goals here. Let me know what questions you have.

Comment thread lib/problems.rb
Comment on lines +3 to 6
# Time Complexity: O(n)
# Space Complexity: O(n)

def balanced(string)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍 Thanks for documenting your source!

Comment thread lib/queue.rb

def enqueue(element)
raise NotImplementedError, "Not yet implemented"
if ((@front == 0 && @back == @size - 1) || (@back == (( @front - 1) % ( @size - 1))))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think this looks a little simpler

Suggested change
if ((@front == 0 && @back == @size - 1) || (@back == (( @front - 1) % ( @size - 1))))
if ((@front == 0 && @back == @size - 1) || (@front == (( @back + 1) % ( @size))))

Comment thread lib/queue.rb
Comment on lines +47 to +51
elsif (@front == @size - 1 )
@front = 0
else
@front += 1
end
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
elsif (@front == @size - 1 )
@front = 0
else
@front += 1
end
else
@front = (@front + 1) % @size
end

Comment thread lib/queue.rb
return @store[@front]
end

def size
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍

Comment thread lib/queue.rb
# end
end

def empty?
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍

Comment thread lib/stack.rb
@@ -1,19 +1,23 @@
class Stack
Copy link
Copy Markdown

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