-
Notifications
You must be signed in to change notification settings - Fork 44
Space - Lee #32
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
base: master
Are you sure you want to change the base?
Space - Lee #32
Conversation
CheezItMan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work Lee. You hit all the learning goals here. Well done. Let me know if you have any questions.
| # Time Complexity: O(n), where n is the length of the string | ||
| # Space Complexity: O(n) | ||
| def balanced(string) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
| @rear = -1 | ||
| end | ||
|
|
||
| def enqueue(element) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
| elsif @rear == @size - 1 && @front != 0 # rear needs to wrap around | ||
| @rear = 0 | ||
| @store[@rear] = element | ||
| else | ||
| @rear += 1 | ||
| @store[@rear] = element | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be simplified a bit.
| elsif @rear == @size - 1 && @front != 0 # rear needs to wrap around | |
| @rear = 0 | |
| @store[@rear] = element | |
| else | |
| @rear += 1 | |
| @store[@rear] = element | |
| end | |
| else | |
| @rear = (@rear + 1) % @store.length | |
| @store[@rear] = element | |
| end |
| elsif @front == @size - 1 # front needs to wrap around | ||
| @front = 0 | ||
| else | ||
| @front += 1 | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above for a way to simplify this.
| @@ -1,19 +1,22 @@ | |||
| class Stack | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Stacks and Queues
Thanks for doing some brain yoga. You are now submitting this assignment!
Comprehension Questions
push(element): Adds an element to the top of the stack;pop: Removes and returns the element on top of the stack;is_empty: Returns true is the stack has no elements, and false otherwise;peekortop: Returns but does not remove the top element of the stack;size: Returns the number of elements on the stackenqueue(element): Puts an element at the back of the queue;dequeue: Removes and returns the element at the front of the queue;is_empty: Returns true if the queue is empty and false otherwise;front: Returns the element at the front, but leaves the queue unchanged;size: Returns the number of elements in the queue.OPTIONAL JobSimulation