Selection Sort Wont Sort
having some problems with the sorting function theres no errors it just wont sort from smallest to largest, does any one know whats wront with it?
1011 97.23
1222 99
2323 68.56
2444 82.77
2555 44.03
3333 83.87
4444 95.7
5151 88.76
6789 78.49
7890 88.34
8999 94.67
9000 99
#include <stdio.h>
#include <stdlib.h>
#define MAX 12
void GetID_Score (int aryID[], float aryScore[]);
void SelectionSort (int aryID[], float aryScore[]);
void PrintAry (int aryID[], float aryScore[]);
int main ()
{
int aryID[MAX] = {0};
float aryScore[MAX] = {0};
GetID_Score(aryID,aryScore);
SelectionSort(aryID,aryScore);
PrintAry(aryID,aryScore);
return 0;
}
void GetID_Score (int aryID[], float aryScore[])
{
/* Local Definition */
FILE* fpLAB1;
int i;
/* Statements */
if ((fpLAB1 = fopen("LAB1.txt", "r")) == NULL)
{
printf("Error opening file\n");
exit (101);
}
for (i = 0; i < MAX; i++)
{
fscanf(fpLAB1, "%d", &aryID);
fscanf(fpLAB1, "%f", &aryScore);
printf("%d %.2f\n", aryID, aryScore);
}
fclose(fpLAB1);
printf("\n\n");
return;
}
void SelectionSort (int aryID[], float aryScore[])
{
/* LD */
int current;
int walker;
int smallest;
int tempData;
float tempData2;
/* ST */
for (current = 0; current < MAX; current++)
{
smallest = current;
for (walker = current + 1; walker <= MAX; walker++)
if(aryID[walker] < aryID[smallest])
smallest = walker;
tempData = aryID[current];
tempData2 = aryScore[current];
aryScore[current] = aryScore[smallest];
aryScore[smallest] = tempData2;
aryID[current] = aryID[smallest];
aryID[smallest] = tempData;
}
return;
}
void PrintAry (int aryID[], float aryScore[])
{
/* LD */
int walker;
/* ST */
for (walker = 0; walker < MAX; walker++)
printf("%d %.2f\n", aryID[walker], aryScore[walker]);
return;
}
1011 97.23
1222 99
2323 68.56
2444 82.77
2555 44.03
3333 83.87
4444 95.7
5151 88.76
6789 78.49
7890 88.34
8999 94.67
9000 99
#include <stdio.h>
#include <stdlib.h>
#define MAX 12
void GetID_Score (int aryID[], float aryScore[]);
void SelectionSort (int aryID[], float aryScore[]);
void PrintAry (int aryID[], float aryScore[]);
int main ()
{
int aryID[MAX] = {0};
float aryScore[MAX] = {0};
GetID_Score(aryID,aryScore);
SelectionSort(aryID,aryScore);
PrintAry(aryID,aryScore);
return 0;
}
void GetID_Score (int aryID[], float aryScore[])
{
/* Local Definition */
FILE* fpLAB1;
int i;
/* Statements */
if ((fpLAB1 = fopen("LAB1.txt", "r")) == NULL)
{
printf("Error opening file\n");
exit (101);
}
for (i = 0; i < MAX; i++)
{
fscanf(fpLAB1, "%d", &aryID);
fscanf(fpLAB1, "%f", &aryScore);
printf("%d %.2f\n", aryID, aryScore);
}
fclose(fpLAB1);
printf("\n\n");
return;
}
void SelectionSort (int aryID[], float aryScore[])
{
/* LD */
int current;
int walker;
int smallest;
int tempData;
float tempData2;
/* ST */
for (current = 0; current < MAX; current++)
{
smallest = current;
for (walker = current + 1; walker <= MAX; walker++)
if(aryID[walker] < aryID[smallest])
smallest = walker;
tempData = aryID[current];
tempData2 = aryScore[current];
aryScore[current] = aryScore[smallest];
aryScore[smallest] = tempData2;
aryID[current] = aryID[smallest];
aryID[smallest] = tempData;
}
return;
}
void PrintAry (int aryID[], float aryScore[])
{
/* LD */
int walker;
/* ST */
for (walker = 0; walker < MAX; walker++)
printf("%d %.2f\n", aryID[walker], aryScore[walker]);
return;
}
0
Comments
Cheers,
Matt