Jump to content

Tutorial: How to walk a path in one line of code


Recommended Posts

Posted

For an array A where:

 

Position A[0] = x

Position A[1]  = y

Position A[2] = z

 

And an empty array B with size 3.

 

Array B after your method:

 

Position B[2] = A[2]

Position B[1] = A[1]

Position B[0] = A[0]

 

->

 

B[0] = A[0] = x

B[1] = A[1] = y

B[2] = B[2] = z

 

A = B 

 

Is that actually necessary?

I was under the impression that they wanted to generate a path that was simply progressing in the opposite direction.

Posted
public <T> void reverse(T[] array) {
	for(int i = 0; i < array.length >> 1; i++) {
		T tmp = array[i];
		array[i] = array[array.length - 1 - i];
		array[array.length - 1 - i] = tmp;
	}
}

 

 

At least someone gets it :P

Any reason why you use a generic instead of an object parameter?

Is it a casting thing?

 

 

Because now the array can be of any type.

Posted

so If I wanted to walk to some location, and also walk from that location to my starting location, I would need to set up two paths?

 

Hey man, the reason there was a discussion on reversing a path was that you can use a path to get somewhere and then simply reverse it to return

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...