Computer Science Canada sorting strings via 2d array |
Author: | SwAnK [ 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
![]() |
Author: | Delos [ Tue Feb 21, 2006 7:03 pm ] |
Post 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...? |
Author: | Clayton [ Tue Feb 21, 2006 7:16 pm ] |
Post 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. |
Author: | MysticVegeta [ Wed Feb 22, 2006 5:25 pm ] |
Post subject: | |
What do you need to sort first of all the numbers or the string? |
Author: | Martin [ Wed Feb 22, 2006 7:09 pm ] |
Post 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 [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] |
Author: | Clayton [ Wed Feb 22, 2006 8:40 pm ] |
Post 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 |
Author: | MysticVegeta [ Thu Feb 23, 2006 2:48 pm ] |
Post 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. |
Author: | Clayton [ Thu Feb 23, 2006 5:36 pm ] | ||||
Post 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.
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:
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 |
Author: | MysticVegeta [ Thu Feb 23, 2006 6:30 pm ] |
Post 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. |