sorting 3d coordinate points

hi guys.
i want to sort a group of points.they are in 3d coordinate.how can i sort them in ascending form? below are my coding. Please hep me. I am still new.this was my assignment.Thanks.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
void CPrimitive::CompareX(CPrimitive *obj,vecf A[],vecf B[],vecf c[])
{
	
	bool sort;
	do{
		sort=false;
		for(int i=0;i<obj->NumTri;i++)
		{
			if(A[i].x > A[i+1].x)
			{
				temp1 = A[i].x;
				A[i].x=A[i+1].x;
				A[i+1].x = temp1;
				sort=true;
			}
		}
	}while(sort);

	
	do{
		sort=false;
		for(int i=0;i<obj->NumTri;i++)
		{
			if(B[i].x > B[i+1].x)
			{
				temp2 = B[i].x;
				B[i].x = B[i+1].x;
				B[i+1].x = temp2;
				sort=true;
			}
		}
	}while(sort);

	do{
		sort=false;
		for(int i=0;i<obj->NumTri;i++)
		{
			if(C[i].x > C[i+1].x)
			{
				temp3 = C[i].x;
				C[i].x = C[i+1].x;
				C[i+1].x = temp3;
				sort=true;
			}
		}
	}while(sort);

}

Generally speaking, if it's more work to read your question than it is to read your code, I never bother to even look at what you're trying to do.
closed account (1yR4jE8b)
How does that even make sense? His question is 2 sentences, and his code is 48 lines...

Anyway, coordinate vectors don't have a natural ordering. So sort them however you want.
Last edited on
Topic archived. No new replies allowed.