sorting using pointer to pointer not working

This is a discussion on sorting using pointer to pointer not working within the C Programming forums, part of the General Programming Boards category; I can't believe this. I am using Code::Blocks 8.02. I added Code: *r_pt_by_SeqNum to the watch window, just as I ...

  1. #16
    Registered User
    Join Date
    Sep 2008
    Posts
    9
    I can't believe this.

    I am using Code::Blocks 8.02.
    I added
    Code:
    *r_pt_by_SeqNum
    to the watch window, just as I did before every time. It displays the member structures, and it still shows garbage for the member struct values except for r_pt_by_SeqNum[0], which is correct.

    BUT adding a watch specifically for a single struct like this
    Code:
    *r_pt_by_SeqNum[i]
    for any i shows the correct value for the sorted member variable seq_num.

    So the code seems to work, but what I am telling Code::Blocks to watch is wrong.
    Watching *r_pt_by_SeqNum shows all structures, but with wrong values.
    ???

    tabstop,
    thank you, thank you, thank you!

  2. #17
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    I still wasn't able to spot the error in your code that makes it sort incorrectly. However I would suggest trying to reproduce the problem with the minimum number of items possible, and then step through the code and see what it is doing.
    Oh wait it was working afterall? Ah no wonder I couldn't find the bug.

    Btw, When you're using integer keys and have lots of them, perhaps a few thousand, then FlashSort beats MergeSort. However if you do look into that, beware of the bugs in the version on neubert.net. You may want to copy the code from my website instead, see my sig.
    RadixSort is another good popular one for when there are a large number of items, but FlashSort is simpler yet more tweakable with regards to the memory usage vs speed tradeoff.
    Or if you want to stick to comparison based techniques, IntroSort is about as good as you can get in the general case.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  3. #18
    Registered User
    Join Date
    Sep 2008
    Posts
    9

    Sorting using pointer to pointer not working - SOLVED

    Thank you all for helping.
    And a big thank you again to tabstop for making me actually look at the values themselves instead of relying blindly on what the IDE showed me.

    To sum it up:

    1. The routine was working all along.

    2. I instructed Code::Blocks to watch
    Code:
    *r_pt_by_SeqNum
    as an array, and it did in fact list the structure array, but with wrong values, except for structure[0]. So I assumed a was seeing the right thing (the array), and that the routine was not working.

    3. tabstop's post resolved the issue: I listed each array[i]->seq_num, and lo and behold, they had the right values.

    4. So I either instructed Code::Blocks incorrectly about what to show, or this is a bug in Code::Blocks. It did list the structures of the array, but did not resolve what the individual pointers in the array pointed to, except for array item[0].

    Now I can get on with the program.
    Thank you all.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting the matrix question..
    By transgalactic2 in forum C Programming
    Replies: 47
    Last Post: 12-22-2008, 03:17 PM
  2. Problems passing a file pointer to functions
    By smitchell in forum C Programming
    Replies: 4
    Last Post: 09-30-2008, 03:29 PM
  3. Replies: 2
    Last Post: 07-11-2008, 08:39 AM
  4. Pointer validity check
    By Carlos in forum Windows Programming
    Replies: 6
    Last Post: 12-11-2003, 03:40 AM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 01:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21