Skip to content

space katem#31

Open
katemyer wants to merge 5 commits into
Ada-C13:masterfrom
katemyer:master
Open

space katem#31
katemyer wants to merge 5 commits into
Ada-C13:masterfrom
katemyer:master

Conversation

@katemyer
Copy link
Copy Markdown

@katemyer katemyer 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? We aren't talking about security but rather Abstact Data Types that allows all data operations to happen at one end only.
Describe a Stack An ordered collection of items where the addition of new items and the removal of existing items always takes place at the same end. For example, shoving towels into the cupboard from the top, always.
What are the 5 methods in Stack and what does each do? push() stores an element in the stack, pop() removes element from the stack, peep() gets the top towel from the linen closet without removing it, isFull() checks if the linen closet is full of towels, and lastly, isEmpty() check is if the linen closet is empty and "someone" needs to do the laundry.
Describe a Queue Think of a line where you add a person to the end of the line (no cutting!) and take someone's order by popping them out of line at the front.
What are the 5 methods in Queue and what does each do? add() someone to the end of the line, offer() inserts a specific person in the line (kind of like allowed cutting), element() returns the person at the front of the line, peek() also returns the person at the front of the line, remove () takes the front of the line out of the line, and poll() tells me who's at the front of the line and also takes them out of the line.
What is the difference between implementing something and using something? Implementing is like carrying a bunch of stuff when you are going to garden: a shovel, a weed wacker, a rake. To use something is to actually use the shovel to dig the dirt to plant your bulbs way late in the season and hope they show up but probably not because you're not that lucky when it comes to gardening outdoors.

OPTIONAL JobSimulation

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

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.

You have some scope problems here which are causing the tests to give errors. You do seem to have the idea mostly down however. So I'd say you hit most of the learning goals here.

Take a look at my comments and let me know what questions you have.

Comment thread lib/problems.rb
#create new stack array
stack_1 = Stack.new
#loop thorugh each character in the string
string.each_char do |char|
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think you have the right idea here, but not quite there.

If the character is an open brace, parens etc. Push it into the Stack.

Otherwise pop the last item off the stack and see if it matches the current character, if it doesn't return false.

Continue until the end of the string.

Comment thread lib/problems.rb
#helper function here
#when you pop, make sure to set it to int
def pop_two_jenga_pieces
value1 = jenga_stack.pop.to_i
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

jenga?

Comment thread lib/problems.rb
operands = { "0" => 0, "1" => 1, "2" => 2, "3" => 3, "4" => 4, "5" => 5, "6" => 6, "7" => 7, "8" => 8, "9" => 9 }
#helper function here
#when you pop, make sure to set it to int
def pop_two_jenga_pieces
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/problems.rb
#loop through the expression
postfix_expression.each_char do |char|
#check if operands are included
if operands.include?(char)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You should make operands a constant so it has global scope. This is failing because this method doesn't have a local variable named operands.

Comment thread lib/queue.rb
end

#example: i want to add myself to a line of 20 people for coffee
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
@@ -1,31 +1,102 @@
class Queue
# set queue_size here to something like 20 or whatever
queue_size = 20
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 should be a constant, the fact that it's not gives you scope problems and failing tests

Comment thread lib/queue.rb
return @front
end

def size
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You can use the positions of front and rear to calculate the size of the queue.

Comment thread lib/stack.rb
@@ -1,19 +1,27 @@
class Stack
Copy link
Copy Markdown

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