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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:15:34+00:00 2026-06-15T06:15:34+00:00

int [] queue1 = {4,7,2,9,12,35,8,49}; int [] queue2 = {24,53,6,19,41,71,1,68,11,32,99} int[]mergeQ = new int[queue1.length

  • 0
    int [] queue1 = {4,7,2,9,12,35,8,49};
    int [] queue2 = {24,53,6,19,41,71,1,68,11,32,99}        
    int[]mergeQ = new int[queue1.length + queue2.length];

    for(int i=0; i < queue1.length; i++ )
    {

      mergeQ[i*2] = queue1[i];       
      mergeQ[i*2+1] = queue2[i];  
    }
    for(int i=0; i < mergeQ.length; i++) {            
        System.out.print(mergeQ[i]+",");
    }

output: 4,24,7,53,2,6,9,19,12,41,35,71,8,1,49,68,0,0,0

how can i print out the rest of elements of queue2.?

  • 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-15T06:15:35+00:00Added an answer on June 15, 2026 at 6:15 am

    Your merge algorithm makes an assumption that queue1.length < queue2.length. Although it is correct for your program, it is not generally a good thing to make such assumptions.

    Change the merge algorithm to go through both arrays until you hit the length of the shorter one, then dump the remaining elements of the longer array into the tail of the merged array. You can do it all in a single loop, like this:

    int p = 0;
    for (int i = 0 ; i < queue1.length || i < queue2.length ; i++) {
        if (i < queue1.length) {
            mergeQ[p++] = queue1[i];
        }
        if (i < queue2.length) {
            mergeQ[p++] = queue2[i];
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

int* p_bob = new int; *p_bob = 78; The above code makes sense to
public int Queue() { using (Entities server = new Entities()) { var ServerId1 =
I'm new at .NET/Threads and I'd like to know if anyone can help me
I have two tables which looks something like this Table Queue int ID; string
I have queue from struct type struct test { int numbers; }; queue<test> q;
I have declared: queue<int, list<int> > Q After a series of calls: Q.push(37); Q.pop();
I'm trying to store the size of a queue in an int in C++.
I have this struct; #define BUFSIZE 10 struct shared_data { pthread_mutex_t th_mutex_queue; int count;
int a = 10; int* pA = &a; long long b = 200; long
int main(void) { char testStr[50] = Hello, world!; char revS[50] = testStr; } I

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.