-
-
Notifications
You must be signed in to change notification settings - Fork 5
Chapter 17 Problems #21
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?
Conversation
/* | ||
This implementation of MyQueue uses the first stack as LIFO order "storage" space. | ||
The second stack is is always in FIFO order. | ||
When the user adds into the MyQueue, the operation is instant. When the user removes from the MyQueue, |
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.
[reviewdog] reported by reviewdog 🐶
Line is longer than 100 characters (found 102).
2. stack2 is empty, so copy over everything from stack1: return the top of stack2 | ||
3. return the top of stack2 | ||
*/ | ||
class MyQueue<E> { |
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.
[reviewdog] reported by reviewdog 🐶
Top-level class MyQueue has to reside in its own source file.
} | ||
|
||
public E remove() throws NoSuchElementException { | ||
if (empty()) |
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.
[reviewdog] reported by reviewdog 🐶
'if' construct must use '{}'s.
if (empty()) | ||
throw new NoSuchElementException("no element in this queue left to remove"); | ||
else if (stack2.empty()) { | ||
while (!stack1.empty()) |
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.
[reviewdog] reported by reviewdog 🐶
'while' construct must use '{}'s.
while (!stack1.empty()) | ||
stack2.push(stack1.pop()); | ||
return stack2.pop(); | ||
} |
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.
[reviewdog] reported by reviewdog 🐶
'}' at column 9 should be on the same line as the next part of a multi-block statement (one that directly contains multiple blocks: if/else-if/else, do/while or try/catch/finally).
} | ||
|
||
public E remove() throws NoSuchElementException { | ||
if (empty()) |
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.
[reviewdog] reported by reviewdog 🐶
'if' construct must use '{}'s.
} | ||
|
||
private E removeHelper() { | ||
if (stack.size() == 1) |
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.
[reviewdog] reported by reviewdog 🐶
'if' construct must use '{}'s.
System.out.println(a); // 4 | ||
try { | ||
a = myQueue.remove(); | ||
} |
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.
[reviewdog] reported by reviewdog 🐶
'}' at column 9 should be on the same line as the next part of a multi-block statement (one that directly contains multiple blocks: if/else-if/else, do/while or try/catch/finally).
|
||
import java.util.NoSuchElementException; | ||
|
||
class MyQueue<E> { |
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.
[reviewdog] reported by reviewdog 🐶
Top-level class MyQueue has to reside in its own source file.
|
||
import java.util.NoSuchElementException; | ||
|
||
class MyQueueV2<E> { |
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.
[reviewdog] reported by reviewdog 🐶
Top-level class MyQueueV2 has to reside in its own source file.
} | ||
|
||
public E remove() throws NoSuchElementException { | ||
if (empty()) throw new NoSuchElementException( |
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.
[reviewdog] reported by reviewdog 🐶
'if' construct must use '{}'s.
if (empty()) throw new NoSuchElementException( | ||
"no element in this queue left to remove" | ||
); else if (stack2.empty()) { | ||
while (!stack1.empty()) stack2.push(stack1.pop()); |
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.
[reviewdog] reported by reviewdog 🐶
'while' construct must use '{}'s.
} | ||
|
||
public E remove() throws NoSuchElementException { | ||
if (empty()) throw new NoSuchElementException( |
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.
[reviewdog] reported by reviewdog 🐶
'if' construct must use '{}'s.
} | ||
|
||
private E removeHelper() { | ||
if (stack.size() == 1) return stack.pop(); |
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.
[reviewdog] reported by reviewdog 🐶
'if' construct must use '{}'s.
Full Name of Contributor (if not apparent from GitHub profile)
Make Queue with 2 Stacks
Make Queue with 1 Stack