| Author |
array
|
bharath pawan
Greenhorn
Joined: Jan 25, 2007
Posts: 11
|
|
|
how to reverse an array with out using indexing
|
 |
Garrett Rowe
Ranch Hand
Joined: Jan 17, 2006
Posts: 1295
|
|
|
Please explain what you mean by "with out using indexing".
|
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32708
|
|
Somebody is having you on, surely? How are you expected to gain access to the elements of an array other than by using their index? If you have two indices to an array, let's call them i and j, it is very easy to swap the two, with a method like this.. . . and once you have got that working it is easy to use that method to reverse the whole array. But I can't think how you are supposed to do it without using the index.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
You could do this in C(++) because of pointer arithmetic, but in Java that doesn't exist.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
Suggested framework: 1. Copy the array to a List (using Arrays.asList) 2. Create a Stack from that List. 3. Create a new empty Stack. 4. Pop entries from the first Stack and push them into the second Stack. 5. Make the second Stack into an array (using List.toArray).
|
 |
Guido Sautter
Ranch Hand
Joined: Dec 22, 2004
Posts: 142
|
|
|
If we're already converting the array into some sort of Java Collection, maybe java.util.Collections provides some useful methods ...
|
 |
 |
|
|
subject: array
|
|
|