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 7773859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:13:58+00:00 2026-06-01T17:13:58+00:00

Basically I’ve been given an implementation of a CircularQueue, I need to implement a

  • 0

Basically I’ve been given an implementation of a CircularQueue, I need to implement a method called ‘public boolean contains (E other)’ which is supposed to return true if the parameter ‘other’ exists in my queue.

I was ok with it because it was an array, but then I saw this other condition to it which is bugging me.

Remember that you cannot freely navigate across all elements in a queue. Only the front element is accessible
at any time through the peek method. Your implementation of the contains and intersectWith methods MUST
NOT make use of any extra queue to temporarily hold some of the elements of this queue.

Would an Iterator be applicable to solve this problem?

Any help is highly appreciated.

Mjall

Solution:

Answer I came up with,
method rotate description:
The method rotate( int n ) removes n elements from the front of the queue and adds them to the rear of the
queue. The elements are added at the rear of the queue in the same order as they are removed from the front
of the queue. For example, given a queue q containing the elements \A, B, C, D, E”, where the element A is
at the front of the queue, following the method call q.rotate( 2 ), the content of the queue will be \C, D, E,
A, B”;

   public boolean contains(E elem) { 

    while( this.isEmpty() != true){

      if(this.peek() == elem){return true;}
      else{rotate(1);}



   } 
   return false;

 }
  • 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-01T17:14:00+00:00Added an answer on June 1, 2026 at 5:14 pm

    An iterator would not be practical for this situation.

    Since it’s a circular queue, you can remember the first thing you’ve seen (not necessarily removing it from the circular queue entirely), and dequeue/enqueue elements until you find what you’re looking for, or arrive at the first dequeued node.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically I have an IFRAME that contains a given page - I want to
Basically I have a field in my table called sex, and it's a boolean.
Basically what I want to do it this: a pdb file contains a location
Basically there is a file called 8puzzle.py and I want to import the file
Basically I'm attempting to add rows to a table, I need to do this
Basically, I have a JTextPane to hold some text which I wish to style.
Basically, I would like a page that consist of a slideshow that contains a
Basically I have a TcxGrid which will be listing various files names and I'd
Basically I need to do String.IndexOf() and I need to get array of indexes
basically: public delegate void RecvCommandHandler (ChatApplication sender, byte[] content); event RecvCommandHandler[] commands = new

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.