Abhishek K Sharma

Greenhorn
+ Follow
since Sep 21, 2014
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Abhishek K Sharma

Hey Chris,
Sure I will do that. I posted the reply thinking that it might be helpful to some other person.
Hi All,

I think we can sort the following way. Not sure about the complexity.

public class SingleLoopSorting {
public static void main(String[] args) {
int arr[] = { 5, 1, 7, 3, 9 };
for (int i = 1; i < arr.length; i++) {
if (arr[i] < arr[i - 1]) {
arr[i] = arr[i] + arr[i - 1];
arr[i - 1] = arr[i] - arr[i - 1];
arr[i] = arr[i] - arr[i - 1];
i = 0;
}
}
System.out.print("Sorted Array : ");
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
}
}