Educational
This page is available for educatinal environment
16/02/2018
Deadline of Submission is on February 19, 2018
so sad :) hahaha
C # soon update ko..
Bz d maka update sa page ko..
Java Program
(Selection Sort)
import java.util.Scanner;
public class selectionsort {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("enter the size of the array: ");
int n = input.nextInt();
int[] x = new int[n];
System.out.println("enter " + n + " numbers:");
for (int i = 0; i < n; i++) {
x[i] = input.nextInt();
}
System.out.print("the sorted numbers:");
Selection(x);
input.close();
}
public static void Selection(int[] arr){
/* advance the position through the entire array */
/* (could do j < n-1 because single element is also min element) */
for(int i=0; i
Java Program
(Insertion Sort)
import java.util.Scanner;
public class insertionsort {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("enter the size of the array: ");
int n = input.nextInt();
int[] x = new int[n];
System.out.println("enter " + n + " numbers:");
for (int i = 0; i < n; i++) {
x[i] = input.nextInt();
}
System.out.print("the sorted numbers:");
insertion(x);
input.close();
}
public static void insertion(int[] arr) {
int i, j, newValue;
for (i = 1; i < arr.length; i++) {
newValue = arr[i];
j = i;
while (j > 0 && arr[j - 1] > newValue) {
arr[j] = arr[j - 1];
j--;
}
arr[j] = newValue;
}
for (int k = 0; k < arr.length; k++) {
System.out.print(arr[k] + " ");
}
}
}
Java Program
(Bubble Sort)
import java.util.Scanner;
public class bubblesort {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("enter the size of the array: ");
int n = input.nextInt();
int[] x = new int[n];
System.out.println("enter " + n + " numbers:");
for (int i = 0; i < n; i++) {
x[i] = input.nextInt();
}
System.out.print("the sorted numbers:");
bubble(x);
input.close();
}
public static void bubble(int[] arr) {
//make arr passes through the array
for (int i = 0; i < arr.length; i++) {
//from the first element to the end
for (int j = 1; j < arr.length; j++) {
//if adjacent items are out of order, swap them
if (arr[j] < arr[j - 1]) {
int temp = arr[j];
arr[j] = arr[j - 1];
arr[j - 1] = temp;
}
}
}
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
}
}
Click here to claim your Sponsored Listing.
Category
Telephone
Website
Address
Sitio Sto Nino Purok 2
Catbalogan
6700