Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #15274

roblem with the algorithm "insertion sort"

From "Roland" <gut@datacomm.ch>
Newsgroups comp.lang.c++
Subject roblem with the algorithm "insertion sort"
Date 2012-04-10 19:12 +0200
Message-ID <4f8469e7_1@news.tiscalinet.ch> (permalink)
Organization Customers of VTX Datacomm AG - http://www.datacomm.ch/

Show all headers | View raw


Hello

I have a problem with the algorithm "insertion sort" in c.

C-Code:

    struct test *sTest

    // vector of struct pointers
    struct test *pt_test[10];
    for (i = 0; i < 10; i++) {
        pt_test[i] = sTest;
        sTest = sTest->next;
    }

    // algorithm "insertion-sort"
    for (n = 1; n < 10; n++) {
        m = n;
        while ((m > 0) && ((strcmp((char*) pt_test[m - 1]->cName, (char*) 
pt_test[n]->cName) > 0))) {
            strcpy((char*)pt_test[m]->cName, (char*)pt_test[m - 1]->cName);
            m--;
        }
        strcpy((char*)pt_test[m]->cName, (char*)pt_test[n]->cName);
    }


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

Thanks a lot

Back to comp.lang.c++ | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

roblem with the algorithm "insertion sort" "Roland" <gut@datacomm.ch> - 2012-04-10 19:12 +0200
  Re: roblem with the algorithm "insertion sort" red floyd <no.spam.here@its.invalid> - 2012-04-10 15:29 -0700
  Re: roblem with the algorithm "insertion sort" MiB <michael.boehnisch@gmail.com> - 2012-04-10 15:53 -0700

csiph-web