Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting a 2-Dimensional Array

Status
Not open for further replies.

jonathanfrascella

Programmer
Sep 25, 2002
11
0
0
GB
I've been following an example for sorting a two dimensional array using QuickSort (from the 4Guys website) but the sorted result is coming through as Rows,Columns where I need to sort by Column,Rows.

The example can be found at and I wondered if anyone can point me the right direction.
 
Sssh - and there I was thinking someone had a constructive reply!!

I've gathered some more information on the array and what's happening/desired output, etc, so please bear with me.


Column orientation should be fixed, but content should be ordered vertically by a given row.
Two-dimensional array in the format (9,x) where:
Dimension 1 is the number of columns (fixed)
Dimension 2 is the number of rows (dynamic)
Example below is (9,3)


Unsorted output.

Col0 Col1 Col2 Col3 Col4 Col5 ... Col9
Prefix Code Description Filetype reserved/blank

ABC MA5212 3description (HTML File)
ABC MA5454 Another description (HTML File)
ABC MA7781 sdglkn sdjgsg sgsfb (HTML File)
ABC MA6144 weowe r, mdsf sdfjh (HTML File)


Sorted output.

Col4 ... Col 9 Col3 Col2 Col0 Col1
reserved/blank Filetype Description Prefix Code

(HTML File) 3description ABC MA5212
(HTML File) Another description ABC MA5454
(HTML File) sdglkn sdjgsg sgsfb ABC MA7781
(HTML File) weowe r, mdsf sdfjh ABC MA6144


Desired sorted output on Col1(code) - note Col1 is ordered, other cols follow suit, but don't break order.

Col0 Col1 Col2 Col3 Col4 Col5 ... Col9
Prefix Code Description Filetype reserved/blank

ABC MA5212 3description (HTML File)
ABC MA5454 Another description (HTML File)
ABC MA6144 weowe r, mdsf sdfjh (HTML File)
ABC MA7781 sdglkn sdjgsg sgsfb (HTML File)


I've got some code to swap the two dimensions of the array over and that works, but the output isn't what's desired.

Input:
Col0, Row0..Col9, Row0
Col0, Row1..Col9, Row1
..
Col0, Row3..Col9, Row3

Output:
Col0, Row0..Col0,Row3
Col1, Row0..Col1, Row3
..
Col9, Row0..Col9, Row3


A database has been suggested as a possible workaround, given it's sorting capabilities but we're trying to keep everything in one place without introducing DB's to the solution(problem).
 
Columns seemed to be a bit out of alignment in the previous post.
Cols 4-9 are blank in the above example.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top