|
-
Jul 21st, 2004, 05:22 AM
#1
Thread Starter
Hyperactive Member
RESOLVED * How to do this the most efficient way
Hi,
What I have is a list with x,y,z coordinates (I.e. x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4.. etc)
I split the list, and put the X, Y, Z coordinates in three seperate arrays: arListX, arListY, arListZ.
The problem is that some coordinates have more then one occurence in the list with coordinates. (x1,y1,z1) = (x3,y3,z3)
What I need to do is to filter out all the double occurences in my list.
And after that I need to have the list sorted.
The sorting has to be done in the order x,y,z
x1 = 50 y1 = 12 z1 = 25
x2 = 75 y2 = 12 z2 = 25
x3 = 50 y3 = 10 z3 = 25
x4 = 60 y4 = 12 z4 = 37
x5 = 30 y5 = 10 z5 = 37
x6 = 60 y6 = 10 z6 = 37
x7 = 60 y7 = 10 z7 = 25
x8 = 60 y8 = 12 z8 = 25
this should become:
x1 = 30 y1 = 10 z1 = 37
x2 = 50 y2 = 12 z2 = 25
x3 = 60 y3 = 10 z3 = 25
x4 = 60 y4 = 10 z4 = 37
x5 = 60 y5 = 12 z5 = 25
x6 = 60 y6 = 12 z6 = 37
x7 = 75 y7 = 12 z7 = 25
Thanks anyway,
mvrp350
Last edited by mvrp350; Jul 21st, 2004 at 07:11 AM.
-
Jul 21st, 2004, 05:27 AM
#2
I would recommend sorting them first, that way any duplicates will be adjacent to each other (and will only require a fairly simple loop).
There are many examples on this forum of sorting, try searching for BubbleSort or QuickSort.
-
Jul 21st, 2004, 06:52 AM
#3
Putting them into three arrays is not helping - it's breaking the "connection" between the values.
Try making an array that is dim'd like COORD(1 to 100,1 to 3)
COORD(1,1) gets the x1 value
COORD(1,2) gets the y1 value
COORD(1,3) gets the z1 value
COORD(2,1) gets the x2 value
COORD(2,2) gets the y2 value
COORD(2,3) gets the z2 value
Before you put a x,y,z combo into the COORD array, loop through all the existing items and see if it's in the array already.
This takes care of dup's - not sorting.
To SORT, since you are looping through the array to find a dup, I would remember what array spot held the first x,y,z that was "greater" than the x,y,z I'm about to put.
Before putting the new x,y,z into the array, I would "open" that held spot, by moving all the items from that spot up one.
SORTING after filling is not needed here, since filling requires dup checking anyway.
There are other ways to do this with collections, etc - but this would be a standard "array" method to use for this action.
-
Jul 21st, 2004, 07:00 AM
#4
Something like this to find duplicates,
VB Code:
Private Const strtemp As String = _
"z2,y2,x1,y1,x1,z1,x2,y2,z2,z2,y3,x3,y3,z3,y3"
Private Sub Command1_Click()
myarray = Split(strtemp, ",")
nextval:
If j > UBound(myarray) Then
Exit Sub
End If
For i = LBound(myarray) To UBound(myarray)
If myarray(i) = myarray(j) Then
If i <> j Then
' If i > j Then
myarray(i) = vbNullString
Next k
' End If
End If
End If
Next i
j = j + 1
GoTo nextval
End Sub
Then could maybe loop through and redim the array if any nulls were found.
-
Jul 21st, 2004, 07:11 AM
#5
Thread Starter
Hyperactive Member
Thanks everybody,
I think I'm going for the combination of your sugestions:
1) use split to put the sting in an array
2) loop through the array to make aones arrXYZ (String)
3) use removeduplicates(arrXYZ) routine I found in this forum to reomve the duplicate entries
4) write a custom sorting routine using a new array in the way that szlamany described.
I do this because this routine will be called very frequently, and the amount of coordinates can go into the 100's.
Using the removeduplicates routine I don't have to loop, because it's using a collection.
My thanks to all of you
-
Jul 21st, 2004, 07:32 AM
#6
You could also use a class of XYZ and store the info into a collection. Then padd the coordinates with zeroes and use the resulting string as the Key in the collection (eg. XYZ-000-000-000). The collection doesn't allow duplicate keys hence .Add will fail for the duplicates... use On Error handling to continue adding the remaining items.
That way you would do a loop only once (through the text file).
-
Jul 21st, 2004, 07:43 AM
#7
Word of caution - collections can be slow.
Arrays of integers or longs are very, very fast.
100's of entries is not a lot - 10000's of entries would be.
But, ultimately, you would be the person that should test different results.
A modificiation of the suggestion I gave would be to not actually move the items up one, to fit the new one in, but instead use a "pointer array" that gets adjusted/incremented.
-
Jul 21st, 2004, 07:49 AM
#8
Adding to collections is slow?
-
Jul 21st, 2004, 07:51 AM
#9
Thread Starter
Hyperactive Member
Thanks for the advice,
I was also looking for a way to use pointer-arrays instead of moveing the items up and down the list.
I'm using longs as the input-type so that shouldn't be any problem
Thanks again
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|