sorting strings via 2d array
Author |
Message |
SwAnK
|
Posted: Tue Feb 21, 2006 6:27 pm Post subject: sorting strings via 2d array |
|
|
alright so i opened a file to get a bunch of data, that kinda looked like so
code: |
11yesnoyes
23nonono
34noyesno
| and so on . i want to sort that using a 2d array, i understand 1d arrays, but not as sure with 2d, the Turing Walkthrough did help a bit. but how do i take that data and throw it into a 2d array and have it come out looken good . thanx |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Delos

|
Posted: Tue Feb 21, 2006 7:03 pm Post subject: (No subject) |
|
|
I've said this before, and I'll say it again:
Contrary to popular belief, we're only partially clairvoyent here. You'll have to be a little more explicit in what you mean by "looken good". What exactly are you doing with your input and why are you using 2D arrays for this purpose? And how does 'sorting' come into all of this...? |
|
|
|
|
 |
Clayton

|
Posted: Tue Feb 21, 2006 7:16 pm Post subject: (No subject) |
|
|
Delos wrote: I've said this before, and I'll say it again:
Contrary to popular belief, we're only partially clairvoyent here. You'll have to be a little more explicit in what you mean by "looken good". What exactly are you doing with your input and why are you using 2D arrays for this purpose? And how does 'sorting' come into all of this...?
i dont know about you but i havent had a single clairvoyance class yet so im out of the loop there, however, you shouldnt use a 2d array here, a single dimension array would work here just fine, so please, if you do in fact have a reason for using a 2d array post the remaining code, but as for sorting, it is the same procedure, just with your array having 2 dimensions instead. I think you may be a bit confused in that you think that two pieces of information go into a 2d array for one locator, but in actuality, only one piece of information goes to each locator. I suggest you look through the Turing Walkthrough again. |
|
|
|
|
 |
MysticVegeta

|
Posted: Wed Feb 22, 2006 5:25 pm Post subject: (No subject) |
|
|
What do you need to sort first of all the numbers or the string? |
|
|
|
|
 |
Martin

|
Posted: Wed Feb 22, 2006 7:09 pm Post subject: (No subject) |
|
|
All a 2d array is is an array of arrays. Similarly, a 3d array is an array of arrays of arrays (ooohhh..).
For example, a 5 element array has five columns each which stores one value.
[ ] [ ] [ ] [ ] [ ]
A 5 x 3 element array has 5 columns storing three values
[ ] [ ] [ ] [ ] [ ]
[ ] [ ] [ ] [ ] [ ]
[ ] [ ] [ ] [ ] [ ] |
|
|
|
|
 |
Clayton

|
Posted: Wed Feb 22, 2006 8:40 pm Post subject: (No subject) |
|
|
MysticVegeta wrote: What do you need to sort first of all the numbers or the string?
if you were to sort the array, you dont have a choice of what to sort, in order to have numbers and letters in the same variable (ex. array (x)) so therefore you would just sort it as a string |
|
|
|
|
 |
MysticVegeta

|
Posted: Thu Feb 23, 2006 2:48 pm Post subject: (No subject) |
|
|
Not necessarily, I dont think you understood what I mean, if the array is 2X2 long which is 1..3, 1..2
and it had data:
arr ("1", "one")
arr ("2", "two")
arr ("3", "three")
Sorting the numbers would give
arr("1", "one")
arr("2", "two")
arr("3", "three")
While sorting the strings would give
arr("1", "one")
arr("3", "three")
arr("2", "two")
Also if you ask how can I sort the numbers, they are strings, you can use strint on the first element of each of the elements. |
|
|
|
|
 |
Clayton

|
Posted: Thu Feb 23, 2006 5:36 pm Post subject: (No subject) |
|
|
and i dont think you understood what i meant, one element of an array can only hold one piece of information, whether it be 1d,2d, or 3d,
ex.
code: |
var myArray:array 1..2,1..2 of string
%so weve created a 2d array
myArray(1,1):="123me"
%so you see, if you are going to sort this you are sorting all of it at once
%as a string, and each element only contains one piece of information
|
therefore your arr("1","one") cannot happen, because:
1) you cannot even code that
2) thats putting more than one piece of information in a single element
Also, when sorting strings with numbers in it, it will still sort the strings in the same manner ex:
code: |
var num1,num2:int:=0
num1:=5
num2:=78
if num1>num2 then
put num1," is bigger"
end if
%this will produce the same result as this
var num1, num2:string:=""
num1:="5"
num2:="78"
if num1>num2 then
put num1+" is bigger"
end if
|
so as you can see, even if numbers are in a string the sort will still sort the numbers numerically (due to their character numbers) which is why sorting strings alphabetically is possible.
so i hope that you now understand what i mean |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
MysticVegeta

|
Posted: Thu Feb 23, 2006 6:30 pm Post subject: (No subject) |
|
|
Ok, I am sorry I used a complicated method of explaining what I was trying to say. I used rows and cols to explain it. what it "meant" was:
1 2 3
one two three
when I refered to arr(x, y) I meant x and y as in elements not their locations. Because then I would have had to tell what each of the elements stored. |
|
|
|
|
 |
|
|