c++ sort/search error

Hello i am new to c++ and this is one of my first programs. I am trying to sort and swap the data[] array by descending sort. I can not move the actual array around though so i have to use the array index[] to reference the positions. In my main i can not seem to pass the parameters over to sort the compiler tells me it is a function compiler error. Is is something simple that i am missing or is there a larger problem? thanks

# include <iostream>


int main() {

int data[] = {0, 130, 210, 200, 400, 300, 205, 140, 120, 190};
int index[100] = {0};
int n = 9; //number of elements

for(int position = 1; 1 <= position <= n; position++){
index[position] = position;
}

sort(data [], index [], n);
return 0;
}


//swaps the positions of data[index[Fus]] with data[index[Iol]]
void Swap(int& x, int& y){
int temp = 0;

temp = x;
x = y;
y = temp;

}


void sort(int data [], int index[], int n) {

int Fus = 0;
int Iol = 0;


for(Fus = 1; Fus < n - 1; Fus++){

for(int position = 1; 1 <= position <= n; position++){
index[position] = position;
}

for(int curIndex = Fus + 1; curIndex < n; curIndex++){

if(data[curIndex] > data[Iol]) {
Iol = data[curIndex];
Swap(data[index[Fus]], data[index[Iol]]);
}
}

for(int curIndex = Fus + 1; curIndex < n; curIndex++){
cout << data[curIndex] << endl;
}
}
}

Care to put that inside code tags and indent it?
PanGalactic+1
Though one thing I can tell you: 1 <= position <= n doesn't make sense. this is evaluated as (1 <= position) <= n where 1 <= position is a boolean. You really don't need that first part. position will never be < 1 as you've set it to 1.
Topic archived. No new replies allowed.