Skip to content

Conversation

@ydunbar
Copy link

@ydunbar ydunbar commented Sep 28, 2020

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 with a specific public interface, but unspecified implementation.
Describe a Stack A Stack is an Abstract Data Type which stores data and allows access in a Last-In-First-Out order (LIFO)
What are the 5 methods in Stack and what does each do? push: Add an element to the top of the stack.
pop: Remove & return the element from the top.
is_empty: returns true if the stack is empty. initialize: creates new LinkedList. to_s: converts to string.
Describe a Queue A Queue is an Abstract Data Structure which stores data and allows access in a First-In-First-Out order (FIFO)
What are the 5 methods in Queue and what does each do? enqueue: add an element to the rear of the queue.
dequeue: Remove & return the element from the front.
is_empty: returns true if the queue is empty. initialize: creates new array of size 20, and declares a front and back. front: return front. size: return size of Queue. to_s: return values in string.
What is the difference between implementing something and using something? A Stack or Queue can be implemented in different ways (unspecified), either using a linked list or an array. But the way they will be used will be the same, with functions that perform the same actions.

OPTIONAL JobSimulation

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

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.

Nice work Yolotzin! You hit the learning goals here. Well done.

Comment on lines +3 to 5
# Time Complexity: O(n)
# Space Complexity: O(n)
def balanced(string)

Choose a reason for hiding this comment

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

👍


def enqueue(element)
raise NotImplementedError, "Not yet implemented"
def enqueue(element) # add an element to the rear of the queue

Choose a reason for hiding this comment

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

👍


def dequeue
raise NotImplementedError, "Not yet implemented"
def dequeue # Remove & return the element from the front

Choose a reason for hiding this comment

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

👍

return @store[@front]
end

def size

Choose a reason for hiding this comment

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

This would be better to return the number of elements in the Queue rather than the size of the internal buffer.

@@ -1,19 +1,19 @@
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