Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Re: roblem with the algorithm "insertion sort"

Reply
Thread Tools

Re: roblem with the algorithm "insertion sort"

 
 
MiB
Guest
Posts: n/a
 
      04-10-2012
On Apr 10, 7:12*pm, "Roland" <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: roblem with the algorithm "insertion sort" red floyd C++ 0 04-10-2012 10:29 PM
Filtered Back Projection Algorithm (FBP Algorithm) Bapaiah Katepalli VHDL 1 06-23-2006 04:50 PM
Word wrap line break code and algorithm for c# Jason Coyne Gaijin42 ASP .Net 0 04-08-2004 07:26 PM
Key generation algorithm and Cipher algorithm Ahmed Moustafa Java 0 11-15-2003 06:35 AM
algorithm problem Adam VHDL 5 11-08-2003 06:26 PM



Advertisments