Skip to content

Instantly share code, notes, and snippets.

@hr1383
Last active December 7, 2015 06:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hr1383/182c78fe963605778b19 to your computer and use it in GitHub Desktop.
Save hr1383/182c78fe963605778b19 to your computer and use it in GitHub Desktop.
change this
for (count; count < arraySize-1; count++) {
for (secondCounter = count + 1; secondCounter < arraySize; secondCounter++) {
if (rec[count].salary > rec[secondCounter].salary) {
temp = rec[count].salary;
rec[count].salary = rec[secondCounter].salary;
rec[secondCounter].salary = temp;
}
}
}
to
// you need to swap the entire record
for (count; count < arraySize-1; count++) {
for (secondCounter = count + 1; secondCounter < arraySize; secondCounter++) {
if (rec[count].salary > rec[secondCounter].salary) {
temp = rec[count];
rec[count] = rec[secondCounter];
rec[secondCounter] = temp;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment