Write a program to sort the elements by using bubble sort.
Answers
Answered by
3
this is only the for loop....
for (int i =o, i <50,i+3)
{
ifa[i]>a[i+1],
a[i]=n,
a[i] =a[i+1],
a[i+1]=n,
}
......thats all ..this bubble sorting for ascending order..... nd in descending order just the in the 'if' statement instead of '>'sign '<' sign will be used thats it.....
HOPE IT HELPS...
for (int i =o, i <50,i+3)
{
ifa[i]>a[i+1],
a[i]=n,
a[i] =a[i+1],
a[i+1]=n,
}
......thats all ..this bubble sorting for ascending order..... nd in descending order just the in the 'if' statement instead of '>'sign '<' sign will be used thats it.....
HOPE IT HELPS...
Answered by
0
//bubble sort 1
class BubbleSort{
public static void main(String args[]){
int num[] = {4,2,7,8,5,9,1,6,11,45};
int tempo;
for(int i = 0; i < 10 - 1; i++){
for(int j = i + 1; j < 10; j++){
if(num[i]>num[j]){
tempo = num[i];
num[i] = num[j];
num[j] = tempo;
}
}
}
for(int i = 0; i < 10; i++){
System.out.println(num[i]);
}
}
}
Hope this helps,
ira.
Similar questions