Hello,
I need help with re-ordering the values in ascending order in the array Unordered. However, I cannot use sort or swap functions. The values in array Index are used as indexes of array Unordered to put the values into the sequence shown in Ordered. I am writing this code for a class and cannot go out of scope; 2D arrays are the farthest ive gotten. So, I can use functions but no classes nor structs.
Unordered: 8 5 32 -6 15
Index: 2 1 4 0 3
Ordered: -6 5 8 15 32
I have written half the code and most likely will not compile.
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
ifstream Input;
ofstream Output;
void ReadValues(int Array[], int N)
{
for(int i = 0; i < N; i++)
Input >> Array[i];
}
void OrderValues(int Unordered[], int Index[], int N)
{
ReadValues(Unordered, N);
ReadValues(Index, N);
for(int i = 0; i < N; i++)
for(int j = 0; j < N, j++)
Ordered[i][j] = {{Unordered[i]}, {Index[j]}};
}
int main()
{
Input.open("input.txt");
Output.open("out.txt");
int size;
Input >> size;
int *Unordered = new int[size];
int *Index = new int[size];
OrderValues(Unordered, Index, size);
Input.close();
Output.close();
return 0;
}