sort array

I am trying to sort in ascending order but can't seem to make this work.

#include <iostream>
#include <fstream>
using namespace std;


int main ( )
{
fstream dataFileI ("Infile1I.txt", ios::in);
fstream dataFileO ("Outfile1O.txt", ios::out);
if(!dataFileI)
{
cout << "Error in opening the input file.\n";
}
if (!dataFileO)
{
cout << "Error in opening the output file.\n";
}
int token , List[25] ;
int position = 0 , number_of_scores ;
double Sum = 0.0 , AVE , Std_Dev, Diff ;
bool ordered = false ;
int n= 0 , k = 0 , x = 0 , y = 0;
dataFileO.setf(ios::fixed) ;
dataFileO.setf(ios::showpoint) ;
dataFileO.precision(2);


dataFileI >> token ;
int highest = 0 ;
int lowest = 100 ;


while (token >= 0)
{
List[position] = token ;
if (token > highest)
{
highest = token ;
}
if (token < lowest)
{
lowest = token ;
}
dataFileI >> token ;
position++;
}
while (ordered == false) {
for (n = 0; n < 25 ; n++){
if (List[n] > List[n+1]){
x = List[n+1];
y = List[n] ;
List[n] = x;
List[n + 1] = y ;
k++; }
if (k == 0)
ordered = true ;
else
k = 0;
dataFileO << List[n] << endl;}
}
return (0) ;
}
I read through that but it still doesn't make sense to me.
I go cross-eyed trying to read your code. Please use [code][/code] from now on.

You can do everything that you're trying to do with
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
while(token >= 0){
	List[position] = token;
	if (token > highest){highest = token;}
	if (token < lowest){lowest = token;}
	dataFileI >> token;
	position++;
}
while(ordered == false){
	for(n = 0; n < 25 ; n++){
		if (List[n] > List[n+1]){
			x = List[n+1];
			y = List[n] ;
			List[n] = x;
			List[n + 1] = y ;
			k++;
		}
		if(k == 0){ordered = true;}
		else{k = 0;}
	dataFileO << List[n] << endl;
}

with a sort( ... , ... , ... );
Just follow the example in there.
Topic archived. No new replies allowed.