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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:18:20+00:00 2026-05-25T13:18:20+00:00

Suppose we have three arrays a , b , and c : int a[1000]

  • 0

Suppose we have three arrays a, b, and c:

int a[1000] = {3,1,5,4};
int b[1000] = {7,9,11,3};
char c[1000] = {'A','B','C','D'};

Array a is then sorted, so it becomes:

a == {1,3,4,5}

Is it possible to arrange for the other two arrays to have their elements rearranged by index, so that they mirror the placement of the sorted elements in the sorted array a? In this example, this should result in

b == {9,7,3,11}
c == {'B','A','D','C'}

How can I achieve this?

  • 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-05-25T13:18:21+00:00Added an answer on May 25, 2026 at 1:18 pm

    you can create a class ABC, which will hold 3 fields: int a, int b, char c.

    implement the operator< for this class, and create a ABC[] of the approppriate size and populate it such that ABC[i] = ABC(a[i],b[i],c[i]).

    implement the operator< so it will compare only a, and use sort on the ABC array.

    after done sorting, you have all your elements in the desired order, just iterate the ABC array and populate the other arrays.

    EDIT:

    simplified [and hard coded] code sample:

    #include <iostream>
    #include <algorithm>
    using namespace std;
    
    class ABC { 
    public: 
      int a,b;
      char c;
      bool operator<(const ABC& other) const { 
        return a < other.a;
      }
    };
    int main() { 
      int a[4] = {3,1,5,4};
      int b[4] = {7,9,11,3};
      char c[4] = {'A','B','C','D'};
      ABC abc[4];
      for (int i = 0; i< 4; i++) { 
        abc[i].a = a[i];
        abc[i].b = b[i];
        abc[i].c = c[i];
      }
      sort(abc,abc+4);
      for (int i = 0; i < 4; i++) { 
        a[i] = abc[i].a;
        b[i] = abc[i].b;
        c[i] = abc[i].c;
      }
      cout << "a= [" << a[0] << ", " << a[1] << ", " << a[2] << ", " << a[3] << "]" << endl;
      cout << "b= [" << b[0] << ", " << b[1] << ", " << b[2] << ", " << b[3] << "]" << endl;
      cout << "c= [" << c[0] << ", " << c[1] << ", " << c[2] << ", " << c[3] << "]" << endl;
      return 0;
    }
    

    works good for me on codepad: http://codepad.org/eCyNkyqR

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

Sidebar

Related Questions

suppose that we have three array int a[]=new int[]{4,6,8,9,11,12}; int b[]=new int[]{3,5,7,13,14}; int c[]=new
Suppose I have two integer arrays a and b with 10 int s per
Suppose we have an array say: int arr[1000]; and I have a function that
Let us suppose i have these three methods defined: int F1(int, int); int F1(float,
Suppose that I have those three files: a.h //a.h header #include <stdio.h> int int_variable;
Suppose I have a string like this: one two three four five six seven
Suppose I have the following arrays: List<int[]> numbers = new List<int[]>(); numbers.Add(new int[] {
Suppose I have an int-array and I want to modify it. I know that
Suppose I have a simple multidimensional structure, like this one: somestr<-array(sample.int(2, 120, replace=TRUE), dim=c(4,5,6))
Suppose I have a C++ class with two private variables. A fixed size array,

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.