Jump to content

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


Alek

Recommended Posts

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.

Link to comment
Share on other sites

Is that actually necessary?

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

 

I don't think you understand what we are saying.  Your method literally just returns the exact same order of the path that you pass to it. No change what so ever.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

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