Skip to content

Julia Kingrey#28

Open
Kalakalot wants to merge 13 commits into
Ada-C12:masterfrom
Kalakalot:master
Open

Julia Kingrey#28
Kalakalot wants to merge 13 commits into
Ada-C12:masterfrom
Kalakalot:master

Conversation

@Kalakalot
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 a data type where the interface is specified but not the implementation. Typically the user has access to methods but implementation is a 'black box'.
Describe a Stack A stack is a "last in, first out" abstract data type typically implemented as a linked link or array. When an item is added to a stack, it goes after / on top of existing items, and when an item is removed, it's always the one that's been on the stack for the least amount of time.
What are the 5 methods in Stack and what does each do? Initialize: defines what data type stack will be implemented as (linked list in this case). Push: adds an element to the end/top of stack. Pop: Removes the element at the end/top of the stack. Empty?: returns true if the stack is empty and false otherwise. to_s: returns the linked list as a string to help test comparisons.
Describe a Queue A queue is a "first in, first out" abstract data type that's also typically implemented as a linked list or array. The first item added to an empty queue stays at the front of the list when additional items are added and is the first element to go when elements are removed.
What are the 5 methods in Queue and what does each do? Initialize: defines the queue's data structure (array in this case), instance variables needed to implement a circular buffer (front index and back index), and a default value for whether the queue is empty. Enqueue: Adds an item to the queue (to the front if the queue is empty, after the most recently added item if not). Dequeue: Removes the item at the front of the queue and returns it. Size: Returns the value used to calculate whether front or back needs to wrap around queue. Empty: Returns true if the queue is empty.
What is the difference between implementing something and using something? Implementing means writing the code. Using means using code someone else has written.

OPTIONAL JobSimulation

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

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.

Problem s with some of your minor Queue methods, but you do have enqueue and dequeue working right. Nice work.

Comment thread lib/problems.rb
Comment on lines +21 to +25
if hash['('] == hash[')'] && hash['{'] == hash['}'] && hash['['] == hash[']']
return true
else
return false
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.

This doesn't quite work as it only counts the number of the characters, not if they're matched.

Comment thread lib/queue.rb
@is_empty = true
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

end

def dequeue
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 front
raise NotImplementedError, "Not yet implemented"
@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.

Suggested change
@front
return @store[@front]

Comment thread lib/queue.rb

def size
raise NotImplementedError, "Not yet implemented"
return @store.length
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 gets you the size of the internal array, not the amount of elements stored in the queue.

Comment thread lib/queue.rb
return @is_empty
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.

Needs to be updated.

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