Thread: resorting an array( matrix)

  1. #1
    Registered User
    Join Date
    Apr 2018
    Posts
    1

    resorting an array( matrix)

    I'm trying to write a code to take a matrix as input and reorganize its rows by sum from lowest to highest.
    so if the matrix is
    2 2 2 (sum 6)
    1 1 3 (sum 5)
    2 5 6 (sum 13)
    then I want it to reorder as
    1 1 3 (sum 5)
    2 2 2 (sum 6)
    2 5 6 (sum 13)
    So far what I did is sum each row and insert it in a one dimension array and sort it from lowest to highest ,but I'm having trouble reordering the original matrix. Any ideas?
    Thanks in advance.
    Last edited by Yuval 2040; 04-29-2018 at 10:01 AM.

  2. #2
    Registered User
    Join Date
    Apr 2018
    Posts
    10
    If you are not allowed to use qsort you need to do almost everything on your own.
    So you might need a function that return the sum of a single row and after this you threat the matrix like a normal array; so you need to write your favourite sorting algorithm but nstead of swapping and comparing the single elements you're going to do it with the rows and the sums of them.

  3. #3
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,907
    Please post your current code, neatly formatted and indented, in [code][/code] tags so we can help you find your problem.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 05-19-2014, 07:32 PM
  2. Array and Matrix check pls
    By Crni An in forum C Programming
    Replies: 7
    Last Post: 09-24-2013, 08:58 PM
  3. Now they're resorting to burgers
    By Yarin in forum General Discussions
    Replies: 37
    Last Post: 11-04-2009, 02:24 PM
  4. Replies: 1
    Last Post: 03-08-2006, 06:47 PM

Tags for this Thread