Thread: sort algorithm stops

  1. #1

    sort algorithm stops

    hi folks,
    i have a li'l problem with some piece of code in a programme... i wrote a sort algorithm (i think it's similar to or the same as bubble sort, no idea...) that suddenly stands still when i use more than ~200 elements in the 3 arrays. i have just changed the variable's names so that you can read this piece without having the whole code- pls don't correct me if i made mistakes with the changed names.

    while(i++ < number_of_strings)
    for(int counter = 0; counter < number_of_strings; counter++)
    if(integer_array[counter] < integer_array[counter + 1])
    integer_buffer = integer_array[counter + 1];
    strcpy(stringbuffer,string_array[counter + 1]);
    integer_array[counter + 1] = integer_array[counter];
    integer_buffer[counter] = integer_buffer;
    integer_buffer = another_int_array[counter + 1];
    another_int_array[counter + 1] = another_int_array[counter];
    another_int_array[counter] = integer_buffer;
    integer_buffer = 0;
    strcpy(string_array[counter + 1],string_array[counter]);
    printf("%s\n", string_array[counter]);

    i use printf to show when the loop stands still.. what do i have to change? how to improve the code so that it works with any number of elements > 200?
    secondary, if no one knows the answer, pls explain the usage of qsort() to me ;-). but the most important thing i wanna know is why my code stands still.
    thank you!

  2. #2
    Registered User
    Join Date
    Sep 2001
    Please post you array definition and their initializations.

  3. #3
    ok, some more infos. first the initializations:

    char string_array[400][20];
    int integer_array[400];
    int another_int_array[400];

    the programme reads an IRC-log-file and then all the nicks; if there's a new nick in the actual line, i increment number_of_strings and copy the name to string_array[number_of_strings];. after i have done this, i increment the element of integer_array[], according to the string. as you can imagine, it counts the lines written by the nick... and the third array is for ,,/me text..``-lines.
    i hope, you can help now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Straight Insertion Sort function problem
    By StaticKyle in forum C++ Programming
    Replies: 6
    Last Post: 05-12-2008, 05:03 AM
  2. Merge Sort Help
    By blindman858 in forum C++ Programming
    Replies: 5
    Last Post: 05-14-2005, 10:47 PM
  3. Sorting
    By vasanth in forum A Brief History of
    Replies: 12
    Last Post: 11-10-2003, 05:21 PM
  4. radix sort and radix exchange sort.
    By whatman in forum C Programming
    Replies: 1
    Last Post: 07-31-2003, 01:24 PM
  5. Bubble Sort, Qucik Sort
    By insomniak in forum C Programming
    Replies: 2
    Last Post: 03-15-2003, 04:54 PM
Website Security Test