Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All tests passed for both files #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

ashtn
Copy link

@ashtn ashtn commented Feb 28, 2017

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
Describe a Stack First in last out (last in first out)
What are the 5 methods in Stack and what does each do?
  1. push - add's element to stack
  2. pop - deletes last element in stack (which is the last element to enter the stack)
  3. top - returns last element in stack
  4. size - returns how many elements are in the stack
  5. empty? - returns true if element is empty, false if not.
    |
    | Describe a Queue | First in first out (Last in Last out) |
    | What are the 5 methods in Queue and what does each do? |
  6. enqueue - add element to queue
  7. dequeue - removes first element in queue
  8. front - tells you first element in queue (first element to enter queue)
  9. size - returns how many elements are in queue
  10. empty? - returns true is queue is empty, false if queue is not empty
    |
    | What is the difference between implementing something and using something? | Implementing would be creating a method and using would be using it |

OPTIONAL JobSimulation

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

@@ -1,22 +1,39 @@
class Queue
attr_accessor :store

Choose a reason for hiding this comment

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

We do not want to do this. This makes @store available outside of the Queue class which means that someone could do something like:

q = Queue.new
# ...stuff here
q.store[2] = 100

So basically it undoes the limitations that we put on accessing/modifying elements in a Queue by letting you directly modify the Queue.

To solve this, just remove this line attr_accessor :store
We similarly wouldn't want it to be attr_reader either

Copy link
Author

Choose a reason for hiding this comment

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

ahhh okay, I think I understand why an attr_accessor is not a good idea but I'm still a bit fuzzy on why attr_reader Isn't a good idea. If I wanted to see the queue contents in literal form, instead of calling ruby q.store # :store in attr_reader I would just do something like ruby puts q ?

Choose a reason for hiding this comment

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

Hopefully class clarified this. If it didn't, let's talk.

@sudocrystal
Copy link

Stacks and Queues

What We're Looking For

Feature Feedback
Implementation of Stack looks complete yes
Implementation of Queue looks complete yes

Looks good

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