Skip to content

Added Ring Queue(=Circular Queue) #322

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

Closed
wants to merge 1 commit into from
Closed

Added Ring Queue(=Circular Queue) #322

wants to merge 1 commit into from

Conversation

YooSeonjae
Copy link
Contributor

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.

@YooSeonjae YooSeonjae mentioned this pull request Dec 17, 2017
Copy link

@christianbender christianbender left a comment

Choose a reason for hiding this comment

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

Good Work! I have some requests.

// Create an array of size n
objArray = new Object[n];
size = 0;
front = 0;

Choose a reason for hiding this comment

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

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;

Choose a reason for hiding this comment

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

The same thing as above.

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)

Choose a reason for hiding this comment

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

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)

Choose a reason for hiding this comment

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

Same thing. Use curly braces

// if the queue is empty throw new IllegalStateException ("The queue is empty");
Object object = new Object();

if (size == 0)

Choose a reason for hiding this comment

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

Use curly braces, too.

if (objArray == null)
return sb.toString();

if (front == rear)

Choose a reason for hiding this comment

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

Use curly braces, too.

public String toString() {
StringBuffer sb = new StringBuffer();

if (objArray == null)

Choose a reason for hiding this comment

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

Use curly braces, too.

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