I am trying to sort a file of 500 structs. I have read them all into an array, but am unable to sort them using a bubble sort. Is there a better way? Here is the function I am using....

void searchArray::sortfile(studarray student, fstream& tempfile,
int length)
{
studarray temp;
int temp1;
int temp2;
int pos;
int placecount;
length = 500;

for(int pos =0; pos < length - 1; pos++)
{
temp1 = pos;

for(placecount = pos + 1; placecount < length; placecount++)

if(student[placecount] < student[temp1])
temp1 = placecount;

temp = student[temp1].Id;
student[temp1] = student[pos];
student[pos] = temp;
}

}

Any help would be appreciated.