Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8688765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:27:41+00:00 2026-06-12T23:27:41+00:00

Im trying to implement a circular array queue without a count variable. Im looking

  • 0

Im trying to implement a circular array queue without a count variable.

Im looking for a way to determine if the array is full, for it to call the expand method but it doesn’t seem to be working any idea why? Thanks!

public void enqueue (T element) {
        if(front != (rear+1) % queue.length) {
            queue[rear] = element;
            rear = (rear+1) % queue.length;
        }
        else
            expandCapacity();
    }

public void expandCapacity() {
        T[] larger = ((T[]) (new Object[queue.length * 2]));

        for (int scan=0; scan < queue.length; scan++) {
            larger[scan] = queue[front];
            front = (front+1) % queue.length;
        }
        front = 0;
        rear = queue.length;
        queue = larger;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T23:27:42+00:00Added an answer on June 12, 2026 at 11:27 pm

    The first thing i see that’s wrong is that in the case where you need to expand, you don’t ever add anything to the queue! The enqueue method needs to look like:

    public void enqueue(T element) {
        if (front == (rear + 1) % queue.length) {
            expandCapacity();
        }
        queue[rear] = element;
        rear = (rear + 1) % queue.length;
    }
    

    In addition, in expandCapacity, you’re setting rear to be one larger than you should; make it:

        rear = queue.length - 1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Greetings, I'm trying to implement a Deque using a circular array that extends when
Trying to implement LoaderManager + CursorLoader. In onFinish method adapter should swap its cursor
I am trying to implement a Circular Doubly Linked List, and I have no
I'm trying to implement a circular buffer in C, and have come across this
I'm trying to replace what I would usually implement as a circular-buffer+. The function
I'm trying implement server code of Server-Sent Events in a generic way that any
I'm trying to implement a circular buffer for use as a frame buffer with
I'm trying to implement a circular buffer for my program. The buffer is used
I'm trying implement a way to recursively template using jsRender. The issue is, my
I'm using Visual c++. I'm trying to implement a circular buffer, this CB must

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.