sorting an array of structures
Bill Heiser
bill at unixland.uucp
Mon Nov 19 09:07:58 AEST 1990
I'm writing a program for a C class, and am looking for tips on how
to sort an array of structures. I understand how to sort a normal
array, but I'm unsure of this one... (it's due in a couple of days,
but I'm working hard to finish it :-)
The structure looks like this:
#define NUMFLIGHTS 100
#define NUMPASSENGERS 500
struct p_rec {
char name[50];
int seats;
};
struct flight {
int flight_num;
int seats_left;
struct p_rec passenger[NUMPASSENGERS];
} flight[NUMFLIGHTS];
I need to print a list of available seats, sorted in order by flight
number. I guess somehow I need to sort the structure based on the contents
of flight_num.
In a different part of the program, I need to sort the passenger list for
a specific flight. I guess in that case I need to get to the right
flight number, then sort the p_rec structure on name.
Any hints/clues/suggestions would be appreciated, especially if they're
before Monday night :-) (it is due on Tuesday).
bill
--
home: ...!{uunet,bloom-beacon,esegue}!world!unixland!bill
bill at unixland.uucp, bill%unixland.uucp at world.std.com
Public Access Unix - Esix SYSVR3 - (508) 655-3848
other: heiser at world.std.com Public Access Unix (617) 739-9753
More information about the Comp.lang.c
mailing list