Java
xxxxxxxxxx
import java.util.Arrays;
import java.util.Scanner;
class Main {
Scanner input = new Scanner(System.in);
void bubbleSort(int array[]) {
int size = array.length;
System.out.println("Choose Sorting Order:");
System.out.println("1 for Ascending \n2 for Descending");
int sortOrder = input.nextInt();
for (int i = 0; i < size - 1; i++)
for (int j = 0; j < size - i - 1; j++)
if (sortOrder == 1) {
// compares the adjacent element
if (array[j] > array[j + 1]) {
int temp = array[j];
array[j] = array[j + 1];
array[j + 1] = temp;
}
}
else {
if (array[j] < array[j + 1]) {
int temp = array[j];
array[j] = array[j + 1];
array[j + 1] = temp;
}
}
}
public static void main(String args[]) {
int[] data = { -2, 45, 0, 11, -9 };
Main bs = new Main();
bs.bubbleSort(data);
System.out.println("Sorted Array in Ascending Order:");
System.out.println(Arrays.toString(data));
}
}
Choose Sorting Order: 1 for Ascending 2 for Descending 1 Sorted Array: [-9, -2, 0, 11, 45]
Linux - كيفية تثبيت anc-api-tools
Linux - كيفية تثبيت curvedns
Python - تحقق مما إذا كان الرقم موجبًا أم سالبًا أم 0
Linux - كيفية تثبيت zenmap
C - عد عدد الأرقام في عدد صحيح
C++ - تحقق مما إذا كان الرقم أوليًا أم لا
JavaScript - تحقق مما إذا كانت السلسلة تبدأ وتنتهي بأحرف معينة
C - ابحث عن أكبر رقم باستخدام تخصيص الذاكرة الديناميكي
C++ - تحقق من السنة الكبيسة
Kotlin - تقريب رقم إلى n منازل عشرية
Kotlin - أوجد عاملي العدد
Java - عكس رقم
Kotlin - عكس رقم
Linux - كيفية تثبيت zfs-test
Linux - كيفية تثبيت xbitmaps
Linux - كيفية تثبيت zstd
Python - كتابة ملفات إكسل (XLSX)
Java - إنشاء الهرم والنمط
We have been online since 2021 and 1 millions of people around the globe have visited our website since then
More visitors every month