array
var
list/contents[0]
proc
Add(item)
if(contents.len == 0)
contents += item
else if(contents.len == 1)
if(item > contents[1])
contents += item
else
contents.Insert(1,item)
else
for(var/i = 1 to contents.len - 1)
var/current = contents[i]
var/next = contents[i+1]
if(next > item && current <= item)
contents.Insert(current,item)
break
mob
verb
test()
var/array/A = new
for(var/i = 1 to 1000)
A.Add(rand(1,i))
for(var/x in A.contents)
src << x
ID:263562
Apr 24 2007, 2:19 pm
|
|
I have alot of data that needs to be sorted often, so I decided to make a datum to do it. However it seems not to work with my test verb.
|
In response to KirbyAllStar
|
|
KirbyAllStar wrote:
I'm not completely sure about how the [] operators work with lists in DM, but in C++ that would make an array with a max size of 0... var/list/L[0] is the equivalent of var/list/L=new (which is the equivalent of var/list/L=new/list as you said). |
In response to Android Data
|
|
Hmmm interesting, which is more efficient or are they the same?
-KirbyAllStar |
In response to KirbyAllStar
|
|
Anyone still know why its not working?
|
In response to Xx Dark Wizard xX
|
|
Yep, I spent quite a while trying to figure it out, but I got it working.
Here's Yours array And Mine array That is assuming that I understood what you wanted...You did want a sorted array right? Thank you very much for giving me this challenge, I understand quite a bit more about lists in DM now. Hope it helps, good luck with whatever your using it for. If you have questions just ask -KirbyAllStar |
In response to KirbyAllStar
|
|
Thanks man, glad I helped you out a bit.
|
In response to Xx Dark Wizard xX
|
|
No Problem
|
This is how I would do it.
That way its a dynamic array, so there is no practical limit to the size.
Hope that helps.
-KirbyAllStar