#include <stdio.h>
#define STRSIZ 30
#define MAXAPP 50
int alpha_first(char *list[], int min_sub, int max_sub);
void select_sort_str(char *list[], int n);
int
main(void)
{
char applicants[MAXAPP][STRSIZ];
char *alpha[MAXAPP];
int num_app,
i;
char one_char;
printf("enter number of applicants (0....%d)\n> ", MAXAPP);
scanf("%d", &num_app);
do
scanf("%c", &one_char);
while (one_char != '\n');
printf("Enter name %d (lastname, firstname): \n", i + 1);
for (i=0; i < num_app; ++i)
gets(applicants[i]);
for (i = 0; i< num_app; ++i)
alpha[i] = applicants[i];
select_sort_str(alpha, num_app);
printf("%-30s%5c%-30s\n", "Application order", ' ',
"Alphabetical order");
for (i = 0; i < num_app; ++i)
printf("%-30s%5c%-30s\n", applicants[i], ' ', alpha[i]);
system("pause");
return(0);
}
int
alpha_first(char *list[],
int min_sub,
int max_sub)
{
int first, i;
first = min_sub;
for (i = min_sub + 1; i <= max_sub; ++i)
if (strcmp(list[i], list[first]) <0)
first = i;
return (first);
}
void
select_sort_str(char *list[], int n)
{
int fill,
index_of_min;
char *temp;
for (fill = 0; fill < n - 1; ++fill){
index_of_min = alpha_first(list, fill, n-1);
if (index_of_min != fill){
temp = list[index_of_min];
list[index_of_min] = list[fill];
list[fill] = temp;
}
}
}
Help with sorting multiple arrays
Page 1 of 11 Replies - 6311 Views - Last Post: 12 July 2011 - 10:20 PM
#1
Help with sorting multiple arrays
Posted 05 July 2011 - 06:20 PM
Okay so I have a problem that I am working on. I need to be able to input names and ages and then have the out put come as the original list, alphabetical list, and numerical by age list. I am having trouble getting the age input and then figuring out how to pass the ages. Can anyone give me direction on how to include the ages too?
Replies To: Help with sorting multiple arrays
#2
Re: Help with sorting multiple arrays
Posted 12 July 2011 - 10:20 PM
Can U Please Explain Your Problem More Clearly?
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|