Skip to content

Earth - Jasmine#13

Open
jasyl wants to merge 5 commits intoAda-C14:masterfrom
jasyl:master
Open

Earth - Jasmine#13
jasyl wants to merge 5 commits intoAda-C14:masterfrom
jasyl:master

Conversation

@jasyl
Copy link

@jasyl jasyl commented Apr 13, 2021

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 concept that has defined external methods but the internal implementation can vary.
Describe a Stack A stack is like a list of items where the first item to enter the stack is the last to leave
What are the 5 methods in Stack and what does each do? Push: Add a new element to the stack, Pop: remove the most recent item that was add, peek: check the last value without removing it, is_empty?: to check if stack is empty, size: return the number of items in the stack
Describe a Queue An Queue is also like a list however, the first item in is the first to go. Similar to people in a line.
What are the 5 methods in Queue and what does each do? Enqueue: add an element to the the queue, Dequeue: remove the first element from the queue, size: return number of items in the queue, is_empty?: return whether the queue is empty or not, peek/front: return the first element without removing it.
What is the difference between implementing something and using something? Implementing is creating the functionality of the object while using is taking advantage of the existing functionality of the object to do something else.

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.

Nice work Jasmine you hit all the learning goals here, plus the extras. Well done!

Comment on lines +3 to 5
# Time Complexity: O(n) - where n is the number of characters in the string
# Space Complexity: O(n) - worse case, all characters are openers and we push them all into the stack.
def balanced(string)

Choose a reason for hiding this comment

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

👍

Comment on lines +38 to 40
# Time Complexity: O(n) - where n is the number of characters in the expression
# Space Complexity: O(n) - We're using a stack to store values.
def evaluate_postfix(postfix_expression)

Choose a reason for hiding this comment

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

👍

@back = -1
end

def enqueue(element)

Choose a reason for hiding this comment

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

👍


end

def dequeue

Choose a reason for hiding this comment

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

👍

return data
end

def front

Choose a reason for hiding this comment

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

👍

return @front == -1 ? 0 : @back - @front + 1
end

def empty?

Choose a reason for hiding this comment

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

👍

return @list[@front]
end

def size

Choose a reason for hiding this comment

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

👍

return @front == -1 || @front == @back
end

def to_s

Choose a reason for hiding this comment

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

👍

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