sorting

This is a discussion on sorting within the C++ Programming forums, part of the General Programming Boards category; Could anyone help me out? I'm trying to sort a double array here, and in QBasic the same style of ...

  1. #1
    Unregistered
    Guest

    sorting

    Could anyone help me out?
    I'm trying to sort a double array here, and in QBasic the same style of code works perfectly but c++ just changes the first number in the 4x5 array and does nothing to the rest.. can anyone see any problems in this code?


    //sort rows of new array in ascending order
    int temp;
    int c;
    for (rr=0;rr<4;rr++){
    for (c=0;c<4;c++){

    for (cc=(c+1);cc<6;cc++){
    if (newmatrix[rr][c]>newmatrix[rr][cc]){
    temp=newmatrix[rr][c];
    newmatrix[rr][c]=newmatrix[rr][cc];
    newmatrix[rr][cc]=temp;
    }
    }
    }
    }

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    412
    Well, you should have cc < 5, not cc < 6 -- otherwise, you'll try to read element [i][5] which is not valid, because your colums are 0 through 4.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 06-11-2009, 12:27 PM
  2. Need help with linked list sorting function
    By Jaggid1x in forum C Programming
    Replies: 6
    Last Post: 06-02-2009, 03:14 AM
  3. sorting structure members using pointers
    By robstr12 in forum C Programming
    Replies: 5
    Last Post: 07-25-2005, 06:50 PM
  4. Still Needing Help : selection sorting
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 10-14-2001, 09:41 PM
  5. selection sorting
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 10-13-2001, 09:05 PM

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