Hi, I really need help with my bubble sorting code, i know the bubble sort is not a good one but i'm a beginner to this.
if anyone can get the code to actually sort the code or at least tell me how to change the code so it works, it's my assignment which has to be next week sometime.. help
#include<stdio.h>
void datain(int, int[10000][4]);
void dataout(int, int[10000][4]);
void sortid( int, int[10000][4], int);
void main()
{
int down, person[10000][4];
/*choose the size of table required*/
printf("Please enter the amount of the people required: \n\r");
scanf("%d",&down);
printf("Amount of people required: %d\n\r",down);
/*validate user input*/
while ((down <=0) || (down > 100000))
{
printf("please re-enter the number of people required:\n\r");
scanf("%d",&down);
}
/*Create database and input data*/
datain(down, person);
/*print out database unsorted*/
dataout(down, person);
/*sort the personnel ID array*/
sortid(down, person, array);
}
void datain(int numberofpeople, int person[10000][4])
{
/*load up person arrays*/
int array1;
for (array1 = 1; array1 <= numberofpeople; array1 ++)
{
printf("\n\rPlease input the person identification: ");
scanf("%d",&person[array1][1]);
printf("Please input the person Wage: ");
scanf("%d",&person[array1][2]);
printf("Please input the person Sex(0 is male and 1 is female): ");
scanf("%d",&person[array1][3]);
/*validate user input*/
while ((person[array1][3] < 0) || (person[array1][3] > 1))
{
printf("please re-enter the sex data\n\r");
scanf("%d",&person[array1][3]);
}
printf("Please input the person Age: ");
scanf("%d",&person[array1][4]);
/*validate user input*/
while ((person[array1][4] < 16) || (person[array1][4] > 65))
{
printf("please re-enter the age data\n\r");
scanf("%d",&person[array1][4]);
}
}
}
/*print out database unsorted*/
void dataout (int number,int person[10000][4])
{
int array;
printf(" \n\r The Unsorted Data:\n");
printf(" ---------------------\n\r");
printf("Personnal ID Wage Sex Age\n\r");
for (array = 1; array <= number; array ++)
{
printf("%10d%10d%10d%10d\n\r",person[array][1],person[array][2],person[array][3],person[array][4]);
}
}
void sort( int number, int person[10000][1], int array)
/*select display from user*/
{
{
char words;
char nochmal;/* this means 'again' in german*/
nochmal = 1;
while (nochmal == 1)
printf("\n\rSelect your form of selection ?");
printf("\n\rAscending by Personnel ID,type id");
printf("\n\rAscending by Wage, type wage");
printf("\n\rAscending by Age, type age");
printf("\n\rFemale data only, print f");
printf("\n\rMale data only, print m\n\r");
scanf("\n%c",&words);
/*sort the array*/ /*here is the bit that doesn't work*/
register int index, array;
for (index = 1; index < number; -- index){
if (person[array-1][1] > person[array][1]) {
/* exchange elements */
index = person[array-1][1];
person[array-1][1] = person[array][1];
person[array][1] = index;
/*to resort the data*/
{
printf("Do you want to sort the database again? Yes (y) or No (n)");
scanf("%d",&nochmal);
}
}
}
}
}