-
Notifications
You must be signed in to change notification settings - Fork 338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
reverse array code did not work #6
Comments
that's right |
Try this.. |
That's right, Here's what the code does: The code declares a new integer array 'a' with some initial values {1, 2, 3, 4, 5, 6, 7, 8}. It declares a new integer array 'b' with the same length as array 'a'. It uses 'a' for loop to iterate through array 'a' from the end to the beginning. During each iteration, it assigns the current value of 'a[i]' to the corresponding position in array 'b', starting from the beginning. Finally, it uses a for-each loop to print out each element in array 'b' in the reversed order. So the output of the program would be:' 8 7 6 5 4 3 2 1'. |
try this public class MyClass {
} |
it is also possible to reverse the same array using constant space with O(n) time complexity .//
|
In for loop of reversing array there should be i-- not i++.
The text was updated successfully, but these errors were encountered: