Skip to content

Space - Nora#26

Open
thenora wants to merge 6 commits intoAda-C13:masterfrom
thenora:master
Open

Space - Nora#26
thenora wants to merge 6 commits intoAda-C13:masterfrom
thenora:master

Conversation

@thenora
Copy link

@thenora thenora commented Sep 9, 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 (ADT) is a type (or class) for objects whose behaviour is defined by a set of value and a set of operations. The definition of ADT only mentions what operations are to be performed but not how these operations will be implemented. It does not specify how data will be organized in memory and what algorithms will be used for implementing the operations. It is called “abstract” because it gives an implementation-independent view. The process of providing only the essentials and hiding the details is known as abstraction
Describe a Stack A stack is a datatype where the last item in, is the first item out.
What are the 5 methods in Stack and what does each do? push: adds an item to the top of the stack. Pop: removes and returns the top item. Empty? Checks if the stack is empty. Size: returns the number of items in a stack. Peek: returns the top item of a stack, but does not remove it.
Describe a Queue A queue is first in, first out.
What are the 5 methods in Queue and what does each do? Enqueue: adds an item to the back of the queue. Dequeue: removes an item from the front of the queue and returns it. Front: Returns the item at the front of the queue without removing it. Empty: Checks if the queue is empty. Size: returns the number if items in the queue.
What is the difference between implementing something and using something? Implementing is essentially design - writing the logic for an abstract data type in a class. Using, means relying on existing designs/classes to execute with specific variables.

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 Nora, you hit all the learning goals here. Well done.

Comment on lines +20 to +28
if char == ')'
return false if top_stack != '('
elsif char == ']'
return false if top_stack != '['
elsif char == '}'
return false if top_stack != '{'
# if the current character is a closing bracket
# return false if the top stack character is not a matching open
end

Choose a reason for hiding this comment

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

Instead of this, you could simplify it with a hash. where the key is the close brace and the matching open brace is the value.

Comment on lines +18 to +19
elsif @store.empty?
raise ArgumentError, "Queue is full"

Choose a reason for hiding this comment

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

Note about the readability here. You raise a Queue is full error if the array is empty?

Comment on lines 49 to 51
def empty?
raise NotImplementedError, "Not yet implemented"
return @front == @back
end

Choose a reason for hiding this comment

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

This reads better if @front == -1 && @back == -1

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