Re: roblem with the algorithm "insertion sort"

Discussion in 'C++' started by MiB, Apr 10, 2012.

  1. MiB

    MiB Guest

    On Apr 10, 7:12 pm, "Roland" <> wrote:
    > Hello
    >
    > I have a problem with the algorithm "insertion sort" in c.
    >

    [..]
    >The problem is now, that this insertion-sort implementation don't works
    >correct.
    >Can you give me a hint?


    1. Separate the algorithm from the data type it sorts. I.e. try to
    create a insertion sort procedure that does not depend on the fact you
    are sorting an array of pointers to structs.
    2. This news group's topic is the language C++, not C. If you're
    really looking for C++ advice, I'd like to note the C++ standard
    library comes with a set of classes that handle strings and containers
    for data objects much more convenient than the somewhat ancient
    strcmp() and strcpy() calls you're using in your implementation
    attempt.
    3. Avoid raw pointers, if you can. The code snippet you gave does not
    depend on dynamically allocated memory and does not implement
    safeguards for handling uninitialized memory or 0-pointers anyway.
    What happens if there are less than 10 objects linked together in the
    sTest chain? Don't get used to this style of programming.
    4. Insertion sort is not a hard algorithm, in fact I cannot think of a
    simpler algorithm for sorting data right now. Refer to the Wikipedia
    article http://en.wikipedia.org/wiki/Insertion_sort and try to
    understand the algorithm before you attempt to implement it [and, I
    feel there is plenty of understanding missing right now, sorry to be
    that direct]. This should do you more good than any copy & paste
    solution provided to you in a reply post to your homework problem.

    best,

    MiB
     
    MiB, Apr 10, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tim923

    insertion sort java code

    Tim923, Apr 12, 2005, in forum: Java
    Replies:
    11
    Views:
    12,139
    bugbear
    Apr 13, 2005
  2. N.
    Replies:
    3
    Views:
    8,753
    charles8784
    Sep 22, 2007
  3. Jochus
    Replies:
    3
    Views:
    517
    Jochus
    Apr 21, 2005
  4. Java Newbie

    Insertion Sort on a linked list

    Java Newbie, Feb 4, 2007, in forum: Java
    Replies:
    2
    Views:
    3,385
    Mark Space
    Feb 9, 2007
  5. red floyd
    Replies:
    0
    Views:
    428
    red floyd
    Apr 10, 2012
Loading...

Share This Page