# Sorting Indices in New Array

Page 1 of 1

## 1 Replies - 1116 Views - Last Post: 15 February 2016 - 11:33 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=388892&amp;s=e714defa5aef030f2efefc051dfcbd39&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Jlinskey

• New D.I.C Head

Reputation: 0
• 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

• I think you'll find it's "Dr"

Reputation: 848
• Posts: 3,402
• 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.