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

  • Home
  • SEARCH
  • 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 8624855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:38:07+00:00 2026-06-12T07:38:07+00:00

I was asked to create a bounded queue class to which the conditions were

  • 0

I was asked to create a bounded queue class to which the conditions were the following:

Using only primitive types, implement a bounded queue to store integers. The data structure should be optimized for algorithmic runtime, memory usage, and memory throughput. No external libraries should be imported and/or used. The solution should be delivered in one class that provides the following functions:

  • constructor – class should provide one method for object creation that takes an integer to set the size of the queue.
  • enqueue – function should take an integer and store it in the queue if the queue isn’t full. The function should properly handle the case where the queue is already full.
  • dequeue – function should return an integer if one is currently stored in the queue. The function should properly handle the case where the queue is empty.

I wrote this class but I wanted to ask for help by having someone test it as well to see if it works properly. I wrote a small main class to test it and everything seems to be working but I want another pair of eyes to look at it before I submit it. Its for an internship. Thank you in advance.

public class Queue<INT>
{


    int size;
    int spacesLeft;
    int place= 0;
    int[] Q;


    public Queue(int size)
    {
        this.size = size;
        spacesLeft = size;
        Q = new int[size];
    }

    //enqueue - function should take an integer and store it in the queue if the queue isn't full.
    //The function should properly handle the case where the queue is already full
    public void enque(int newNumber) throws Exception
    {
        if(place <= size)
        {
            Q[place] = newNumber;
            place++;
            spacesLeft--;

        }
        else
            throw new Exception();
    }


    //dequeue - function should return an integer if one is currently stored in the queue. 
    //The function should properly handle the case where the queue is empty.
    public int deque() throws Exception
    {
        int dequeNum;


        if(spacesLeft == size)
            throw new Exception();
        else
        {
            dequeNum = Q[0];
            spacesLeft++;
        }

        int[] tempAry = new int[size];  
        for (int i=0; i < Q.length; i++)
        {  
            if(i < size-1)
            {
                tempAry[i] = Q[i+1]; // put in destination  
            }

        }

        Q = tempAry;

        for(int i = 0; i < Q.length; i++)
        {
            System.out.println("value in Q"+Q[i]);

        }


        return dequeNum;


    }
}
  • 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-12T07:38:08+00:00Added an answer on June 12, 2026 at 7:38 am

    Here is the implementation that as per your specifications.

    Queue

    Here is the source code for the same.

    import java.util.Arrays;
    
    public class Queue {
    
        private int enqueueIndex;// Separate index to ensure enqueue happens at the end
        private int dequeueIndex;// Separate index to ensure dequeue happens at the
                                // start
        private int[] items;
        private int count;
        // Lazy to add javadocs please provide
        public Queue(int size) {
            enqueueIndex = 0;
            dequeueIndex = 0;
            items = new int[size];
        }
        // Lazy to add javadocs please provide
        public void enqueue(int newNumber) {
            if (count == items.length)
                throw new IllegalStateException();
            items[enqueueIndex] = newNumber;
            enqueueIndex = ++enqueueIndex == items.length ? 0 : enqueueIndex;
            ++count;
        }
        // Lazy to add javadocs please provide
        public int dequeue() {
            if (count == 0)
                throw new IllegalStateException();
            int item = items[dequeueIndex];
            items[dequeueIndex] = 0;
            dequeueIndex = ++dequeueIndex == items.length ? 0 : dequeueIndex;
            --count;
            return item;
        }
    
        @Override
        public String toString() {
            return Arrays.toString(items);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was asked to create a class that implement a queue of jobs using
I have been asked to create some functionality in which marketing team send users
I was asked to create a very simple dashboard using a Sharepoint list as
Ive been asked to create a website mock-up using Photoshop, but I'm not sure
I've been asked to create a stand-alone webapp using straight HTML and Javascript that
I've been asked to create a financial report, which needs to give a total
I am asked to create a few small websites using nanoc3 like http://www.pancakeaircompressor.org/ ,
I was asked to create a cleanup target using NAnt that would remove files
I was recently asked to create a web page using a static website generator,
Background: for my computer science class, we were asked to create a program that

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.