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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T13:28:17+00:00 2026-05-10T13:28:17+00:00

I would like to sort an array in ascending order using C/C++ . The

  • 0

I would like to sort an array in ascending order using C/C++. The outcome is an array containing element indexes. Each index is corespondent to the element location in the sorted array.

Example

Input:  1, 3, 4, 9, 6 Output: 1, 2, 3, 5, 4 

Edit: I am using shell sort procedure. The duplicate value indexes are arbitrarily chosen based on which duplicate values are first in the original array.

Update:

Despite my best efforts, I haven’t been able to implement a sorting algorithm for an array of pointers. The current example won’t compile.

Could someone please tell me what’s wrong?

I’d very much appreciate some help!

void SortArray(int ** pArray, int ArrayLength)  {     int i, j, flag = 1;    // set flag to 1 to begin initial pass     int * temp;    // holding variable orig with no *          for (i = 1; (i <= ArrayLength) && flag; i++)     {         flag = 0;         for (j = 0; j < (ArrayLength - 1); j++)         {             if (*pArray[j + 1] > *pArray[j])    // ascending order simply changes to <             {                  &temp = &pArray[j];    // swap elements                 &pArray[j] = &pArray[j + 1];    //the problem lies somewhere in here                 &pArray[j + 1] = &temp;                 flag = 1;    // indicates that a swap occurred.             }         }     } }; 
  • 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. 2026-05-10T13:28:18+00:00Added an answer on May 10, 2026 at 1:28 pm

    Since you’re using C++, I would do it something like this. The SortIntPointers function can be any sort algorithm, the important part is that it sorts the array of pointers based on the int that they are pointing to. Once that is done, you can go through the array of pointers and assign their sorted index which will end up in the original position in the original array.

    int* intArray; // set somewhere else int arrayLen;  // set somewhere else    int** pintArray = new int*[arrayLen]; for(int i = 0; i < arrayLen; ++i) {     pintArray[i] = &intArray[i]; }  // This function sorts the pointers according to the values they // point to. In effect, it sorts intArray without losing the positional // information. SortIntPointers(pintArray, arrayLen);  // Dereference the pointers and assign their sorted position. for(int i = 0; i < arrayLen; ++i) {     *pintArray[i] = i; } 

    Hopefully that’s clear enough.

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

Sidebar

Ask A Question

Stats

  • Questions 133k
  • Answers 134k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You will have to do an each around all slideshows… May 12, 2026 at 6:43 am
  • Editorial Team
    Editorial Team added an answer OProfile and its ancestor DPCI were developed for profiling production… May 12, 2026 at 6:43 am
  • Editorial Team
    Editorial Team added an answer Works in both Oracle and SQL Server, I believe is… May 12, 2026 at 6:43 am

Related Questions

My apologies if this has been answered before or is obvious...did some searching here
I would like to sort an array of strings in a directory, given a
I am practicing using pointers. I have a pointer to an array of 3
I need to sort an array containing a list of words and search the

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.