1 Replies - 939 Views - Last Post: 15 February 2016 - 11:33 PM Rate Topic: -----

#1 Jlinskey  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 15-February 16

Sorting Indices in New Array

Posted 15 February 2016 - 02:23 PM

Let's say I have an array A = {6.5, 2.2, 5.6, 7.1}. How would I go about placing the ordered indices of array in a new array, without changing the original contents of A? So, B would equal to {1, 2, 0, 3}.

Edit: My current code just orders the original array itself.


int main(){
    int temp;
    const int N = 6;
    int arr[N] = {6.5, 2.2, 5.6, 7.1};
    int sortedIndex[N];
    for (int i = 0; i < N; i++){
         for (int j = i + 1; j < N; j++){
             if (arr[j] < arr[i]){
                 temp = arr[i]
                 arr[i] = arr[j]
                 arr[j] = temp; }
    {
    return 0;
}

This post has been edited by macosxnerd101: 15 February 2016 - 11:06 PM
Reason for edit:: Please use code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Sorting Indices in New Array

#2 ndc85430  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 563
  • Posts: 2,304
  • Joined: 13-June 14

Re: Sorting Indices in New Array

Posted 15 February 2016 - 11:33 PM

Well, you aren't doing anything with sortedIndex. Describe first how you'd do the task with pen and paper; that usually helps.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1