Skip to content

Branches - Diana Han#26

Open
dhan0406 wants to merge 5 commits into
Ada-C12:masterfrom
dhan0406:master
Open

Branches - Diana Han#26
dhan0406 wants to merge 5 commits into
Ada-C12:masterfrom
dhan0406:master

Conversation

@dhan0406
Copy link
Copy Markdown

@dhan0406 dhan0406 commented Mar 2, 2020

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 is a data type that specifies an external interface and it's described by its methods and how they perform. It does not specify how it's build internally or implemented.
Describe a Stack Stack is an ADT in which elements follow the LIFO rule, last in first out.
What are the 5 methods in Stack and what does each do? Initialize creates the empty stack class. Push adds an element to the top of the stack. Pop removes and returns the last added element at the top of the stack. Empty? return true is the stack is empty. To_s returns the stack in a string format.
Describe a Queue Queue is an ADT in which elements follow the FIFO rule, first in first out.
What are the 5 methods in Queue and what does each do? Initialize creates a queue, in this case the default size was set at 50. Enqueue adds and element to the back of the queue. Dequeue removes and returns the first element. Empty? returns true if the front == back. To_s returns the elements in a string format, after removing the nil spaces.
What is the difference between implementing something and using something? An example of implementation is how we build the Stack and Queue class creating their methods. Using it would be when we call these methods on data types without knowing HOW it's being done.

OPTIONAL JobSimulation

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

@dhan0406
Copy link
Copy Markdown
Author

dhan0406 commented Mar 6, 2020

Hi Chris! Can I get more time to revise methods where I'm failing the tests, I can get them done by EOD!

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.

Nice work, you hit all the learning goals here. Very nice work with the circular buffer.

Comment thread lib/problems.rb
Comment on lines 3 to 5
# Time Complexity: ?
# Space Complexity: ?
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.

👍

Comment thread lib/queue.rb
@front = @back = -1
end

def enqueue(element)
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

def dequeue
raise NotImplementedError, "Not yet implemented"
def dequeue #remove and return from front
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

def size
raise NotImplementedError, "Not yet implemented"
@back - @front
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This works when front < back. What about when back has wrapped around the buffer.

Comment thread lib/queue.rb
Comment on lines +45 to +47
if @front == @back
return true
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
if @front == @back
return true
end
return @front == @back

Comment thread lib/queue.rb
end
end

def to_s
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍 Well done

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