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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:51:02+00:00 2026-06-14T16:51:02+00:00

When creating 2 Queues like this: ArrayQueue q1 = new ArrayQueue(); ArrayQueue q2 =

  • 0

When creating 2 Queues like this:

    ArrayQueue q1 = new ArrayQueue();
    ArrayQueue q2 = new ArrayQueue();
    for (int i = 0; i < 5; i++) {
        q1.enqueue(new Integer(i));
    }
    for (int i = 5; i < 10; i++) {
        q2.enqueue(new Integer(i));
    }
    System.out.println("q1: " + q1);
    System.out.println("q2: " + q2);

It outputs: q1: 4,3,2,1,0 and q2: 9,8,7,6,5.

I need a method that merges Queue q2 into Queue q1 with interleaved elements.
So if println‘d again would output: q1: 0,5,1,6,2,7,3,8,4,9 and q2: 9,8,7,6,5.

My class contains all the appropriate methods enqueue, dequeue, peek, isEmpty, size, doubleSize… my method name is:

    public void mergedQs(ArrayQueue q) {
    }

Basically i want to add objects to two queues, then merge the second queue into the first(not just add them).
Ideally i want to avoid casting them or using an ArrayList as i want them to remain Queues.

  • 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-14T16:51:06+00:00Added an answer on June 14, 2026 at 4:51 pm

    You might find this useful. It merges any number of queues.

    public static <T> Queue<T> mergeQs(Queue<T> ... qs) {
        Queue<T> ret = new ConcurrentLinkedQueue<T>();
        boolean more;
        do {
            more = false;
            for (Queue<T> q : qs) 
                if (!q.isEmpty()) {
                    ret.add(q.remove());
                    more = true;
                }
        } while(more);
        return ret;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently creating a quote system which works like this: User submits data
I'm creating an array of Thread::Queue elements. I'm doing that like this: for (my
I like the Distpatcher in the System.Windows.Threading namespace, and would like to use this
I am creating an PriorityQueue with multiple queues. I am using an Array to
Creating a class at runtime is done as follows: klass = Class.new superclass, &block
(creating a separate question after comments on this: Javascript redeclared global variable overrides old
Say for an example, I've a list like this: q_list = [('94.vmtest2', 'sgmops', 'Andy
I’m writing a server/client game, a typical scenario looks like this: one client (clientA)
I'm creating an application that I want to put into the cloud. This application
I'm creating an application in Swing using NetBeans. I would like to be able

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.