Quick Sort for a Struct

Home Forums C Programming Quick Sort for a Struct

This topic contains 2 replies, has 2 voices, and was last updated by  GWILouisaxwzkla 8 years, 10 months ago.

  • Author
    Posts
  • #2168

    DixieFuqua
    Member

    Hey i am new to c plus plus, and really need some help!
    Basically i have information, in a file, first name, second name and idnumber stored in a struct for a number of people as such:

    struct person {
    char idnumber [numbersize];
    char firstname [namesize];
    char secondname [namesize];

    };

    And i need to be able to sort it according to either first name, second name or in ascending idnumber using a quick sort. Is it possible to write a general function and use pointers to assign the relevant piece of information to sort by e.g first name etc?. Then, is it possible to call the function and print the sorted list?

    If someone could show me some helpful code or some hints it would be greatly appreciated.
    Thanks.

  • #3498

    The structs will form a linked list , correct? The sorting key will be variable amongst the struct field members ( the user will chose a struct member to sort the data on ) ?? Is the list to be “disconnected” for sorting ( structs will be moved and the list reconnected ) or is data to be shifted ( probably easier )…

  • #3499

    Heres a way to do this with a doubly linked list with quicksort. This version of quicksort uses the last item in the
    list as a pivot element when partitioning.

    input:

    output ( sorting with first name as key ):

You must be logged in to reply to this topic.

0 Shares
Share
+1
Tweet
Share
Stumble