Repository navigation
Added Ring Queue(=Circular Queue) - #322
Closed
YooSeonjae wants to merge 1 commit into
Closed
YooSeonjae wants to merge 1 commit into
YooSeonjae wants to merge 1 commit into
Conversation
Closed
christianbender
requested changes
Mar 31, 2018
christianbender
left a comment
There was a problem hiding this comment.
Good Work! I have some requests.
| // Create an array of size n | ||
| objArray = new Object[n]; | ||
| size = 0; | ||
| front = 0; |
There was a problem hiding this comment.
The problem is that for (front+1) % objArray.length the pointer front never reaches the element with index 0 of the array. I would front set equal to -1.
| objArray = new Object[n]; | ||
| size = 0; | ||
| front = 0; | ||
| rear = 0; |
| public void add(Object obj) { | ||
| // type obj if there is empty space in the queue | ||
| // if there is no empty space in the queue throw new IllegalStateException ("The queue is full"); | ||
| if (size == objArray.length) |
There was a problem hiding this comment.
Please use curly braces. See here for if-else: http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-142311.html#449
| public Object first() { | ||
| // return the first element if the queue is not empty | ||
| // if the queue is empty throw new IllegalStateException ("The queue is empty"); | ||
| if (size == 0) |
| // if the queue is empty throw new IllegalStateException ("The queue is empty"); | ||
| Object object = new Object(); | ||
|
|
||
| if (size == 0) |
| if (objArray == null) | ||
| return sb.toString(); | ||
|
|
||
| if (front == rear) |
| public String toString() { | ||
| StringBuffer sb = new StringBuffer(); | ||
|
|
||
| if (objArray == null) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
circular queue or ring queue is a data structure that uses a single, fixed-size buffer as if it were connected end-to-end.
When you show a queue with an array using the Ring Queue, it shows that when you call remove (), there is no need to move a lot because of its free space.