Need help with linked list sorting function

Printable View

I'll let you think about that much for now.
  • 06-01-2009
    Whoa, I should have previewed that. Code tags don't work so well inside a bullet list!
    The 3 lines are:

    plat1 = first;
    plat3 = first;
    (*plat3).next = plat1;

  • 06-02-2009
    Thank you both for taking the time to look at my code and respond.

    @ c.user:
    I'm assuming that by telling me to change '(*first).name' to 'first->name' you're asking me to change the format I'm using for all instances of (*[pntr]).name, since I can't find a use of '(*first).name' anywhere in my code aside from a set of comments I used to hide away a test to see if my lists were being properly copied. If so, then why? I was told there was no difference between using either styles.

    @ iMalc:
    The first two ('plat1= first;' and 'plat3 = first:') are meant to return the two "platforms" to the beginning of the linked list so that they're ready for a second round of sorting. The third piece of code you mentioned ('(*plat3).next = plat1;')

    ...[minutes later]...

    Was part of the problem! I was trying to make sure that at the first sort of every round 'plat3' would be at the very beginning of the list alongside 'first' and connected to plat1, which at the time would be the next "platform" up, right after 'first,' plat3, and plat2, but I didn't realize that plat3 didn't change its location when I assigned plat2 to 'first', and was actually still with plat1 when I assigned it's own location to its next. (So stupid of me, and the codes in question were right next to each other...)

    ...Oh, so that's what c.user meant with "in this moment you will loop first element to itself". I wasn't sure what the "first element" was.

    Anyways, after noticing that, I realized that my plat3 wasn't moving alongside the other plats properly. It should be that as the plats moved forward, plat3 would be connected to plat1, and plat1 to plat2, but I never wrote the code to move plat3 up, and thus my plat3 wasn't connecting properly whenever a sort took place.

    So what it needed was to get rid of the '(*plat3).next' and have a 'plat3 = plat2' before the i++!

    Thank you both so much, my sort function works perfectly now.

    Also, after thinking about it for a minute, you're right iMalc, an insertion style sorting would have actually been much, MUCH easier.
  • 06-02-2009
    -> - is special operation for this
    the difference is



    in this case (*first). you are permitted (by one level) and must write same code with (*...) every time
    in substructures you can go through the substructures for get the deepest element, it is more comfortable to do by the arrows
  • 06-02-2009
    Oh, I see now. I'll keep that in mind, seems like I'll have to make a habit of it for future use.