Thread: confused with sorting struct

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    115

    confused with sorting struct

    hi guys, anyone see what is wrong with this, i can implement this without structs but using structs i can not do it.

    thanks!

    Code:
    void swap( student_t *fval, student_t *sval )
    {
    	student_t temp;
    	temp = *fval;
    	*fval = *sval;
    	*sval = temp;
    }
    Last edited by kurz7; 05-18-2003 at 02:47 AM.
    there are only 10 people in the world, those who know binary and those who dont

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    What are you trying to swap? Your swapping as listed here only swaps the value. As such, the ID doesn't get changed, the ID just gets a different value assigned to it. Is this really what you want? Or are you trying to swap the whole structure / contents?

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    115
    sorry i didnt make the problem clear, all i wanted to do was sort the structure from lowest mark to highest mark with student id respectively
    there are only 10 people in the world, those who know binary and those who dont

  4. #4
    Registered User
    Join Date
    Jan 2003
    Posts
    115
    hi ive fixed up my code but i cant seem to swap the elements in the array. anyone can help?

    in my swap function how do i make it so i can swap the structure in the array? for example if element 1 is bigger then element 2 in the array, i want to swap the elements around. so element 2 jumps into slot 1 and element 1 goes in slot 2...

    THANKS!
    there are only 10 people in the world, those who know binary and those who dont

  5. #5
    Registered User
    Join Date
    Jan 2003
    Posts
    115
    ops i didnt see that
    THANKS! Salem
    there are only 10 people in the world, those who know binary and those who dont

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Concatenating in linked list
    By drater in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 11:10 PM
  2. Sorting Linked Lists
    By DKING89 in forum C Programming
    Replies: 6
    Last Post: 04-09-2008, 07:36 AM
  3. Help please im stuck
    By ItsMeHere in forum C Programming
    Replies: 7
    Last Post: 06-15-2006, 04:07 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. My final data does not display
    By p1c1078 in forum C Programming
    Replies: 3
    Last Post: 04-23-2003, 06:32 AM