Selection Sort PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

BUBBLE SORT

import java.io.*;
1. public class Ascending _Order
2. {
3. public static void main()throwsIOException
4. {
5. int n, temp;
6. DataInputStream ak = new DataInputStream(System.in);
7. System.out.print("Enter no. of elements you want in array:");
8. n =Integer.parseInt(ak.readLine());
9. int a[] = new int[n];
10. System.out.println("Enter all the elements:");
11. for (int i = 0; i < n; i++)
12. {
13. a[i] = s.nextInt();
14. }
15. for (int i = 0; i < n; i++)
16. {
17. for (int j = i + 1; j < n; j++)
18. {
19. if (a[i] > a[j])
20. {
21. temp = a[i];
22. a[i] = a[j];
23. a[j] = temp;
24. }
25. }
26. }
27. System.out.print("Ascending Order:");
28. for (int i = 0; i < n - 1; i++)
29. {
30. System.out.print(a[i] + ",");
31. }
32. System.out.print(a[n - 1]);
33. }
34. }

You might also like