Thread: sorting

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