Wednesday, September 20, 2017

Bubble Sort in Turbo Pascal

A program that I wrote using Pascal as my programming language that will ask the user how many items to be sorted and then our program will display the original arrangement of the numbers and finally it will display the sorted arrangement of numbers on our screen. I am using bubble sort algorithm to sort the given numbers by our user. I am using Turbo Pascal for Windows as my programming environment. I hope you will find my work useful. Thank you.

I am currently accepting programming work kindly contact me in the following email address for further details. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.






Sample Program Output


Program Listing

bubble.pas

Program Bubble_Sort;
uses Wincrt;

const
items = 100;

type
 values = array[1..items] of integer;

var
num,a,b  : integer;
list_items     : values;
min            : integer;
temp           : integer;


Begin
writeln;
writeln('Bubble Sort Program in Turbo Pascal');
writeln;
writeln;
writeln('Written By: Mr. Jake R. Pomperada');
writeln;  
write('How many items ?  '); 
readln(num);
for a:= 1 to num do
begin
    write('Give value in item number ',a,' : ');
    read(list_items[a]);
end;
    writeln;
    writeln;
    writeln('Orignal Arrangement of Values : ');
    writeln;
for a:=1 to num  do
    write(list_items[a],' ');

{============ Bubble Sort Ascending Order ===================}

for a:=1 to num-1 do
begin
     for b:= num downto a+1 do
     begin
          if list_items[b] < list_items[b-1] then
          begin
            Temp:=list_items[b];
            list_items[b]:=list_items[b-1];
            list_items[b-1]:=temp;
          end;
     end;
end;

writeln;
writeln;
writeln('Arrangement of Values Using Bubble Sort ');
writeln;
for a := 1 to num do
begin
write(list_items[a],' ');
end;

writeln;
writeln;
write('End of Program');
writeln;
readln;
End.



Thursday, September 14, 2017

Bucket Sort in Java

Here is the implementation of Bucket Sort using Java as my programming language. Our program will ask the user how many items to be sorted and then it will ask the user to give a series of numbers and then it will be sorted using selection sort algorithm. I hope you will find my work useful. 

I am currently accepting programming work kindly contact me in the following email address for further details. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.





Sample Program Output


Program Listing

Bucket_Sorting.java

/**
 * 
 */
package bucket_sort;

import java.util.Scanner;

/**
 * @author Jake R. Pomperada
 * Bacolod City, Negros Occidental, Philippines
 * September 14, 2017  Thursday
*/


public class Bucket_Sorting {

/**
* @param args
*/
public int[] bucket_sort_demo(int[] array) {
    
   int[] bucket = new int[10000];   

 
   for (int i = 0; i < array.length; i++)
       bucket[array[i]]++;

   int outPos = 0;
   for (int i = 0; i < bucket.length; i++) { 
    if (bucket[i] > 0)
        array[outPos++] = i;
   }
    
   return array;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
 
Bucket_Sorting bSort = new Bucket_Sorting();      
System.out.print("\n\n");
System.out.print("===== Bucket Sort in Java ====");
System.out.print("\n\n");
System.out.print("===== Written By: Mr. Jake R. Pomperada =====");;
System.out.print("\n\n");
System.out.print("How many items? : ");
        int num = input.nextInt();
        int numbers[] = new int[num];

System.out.println();
        for (int i = 0; i < num; i++) {
            System.out.print ("Give value in item no. " + (i+1) + " : ");
            numbers[i] = input.nextInt();
        }

        System.out.print("\n\n");
System.out.print("Original Number Arrangements" );
System.out.print("\n\n");
        for (int temp : numbers){
        System.out.print(temp);
            System.out.print(", ");
        } 
        System.out.print("\n\n");
System.out.print("Sorted Number Arrangements" );
System.out.print("\n\n");
        
int[] sortedArray = bSort.bucket_sort_demo(numbers);
 
        for(int a:sortedArray){
            System.out.print(a);
            System.out.print(", ");
}
        input.close();
}

}




Wednesday, September 13, 2017

Merge Sort in Java

Here is the implementation of Merge Sort using Java as my programming language. Our program will ask the user how many items to be sorted and then it will ask the user to give a series of numbers and then it will be sorted using selection sort algorithm. I hope you will find my work useful. 

I am currently accepting programming work kindly contact me in the following email address for further details. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.






Sample Program Output


Program Listing

/**
 * 
 */
package merge_sort;

import java.util.Scanner;

/**
 * @author Jake R. Pomperada
 * Bacolod City, Negros Occidental, Philippines
 * September 13, 2017   Wednesday
*/


public class Merge_Sorting {

/**
* @param args
*/
public static void merge_sort(int[] arr, int low, int high) 
    {
        int N = high - low;         
        if (N <= 1) 
            return; 
        int mid = low + N/2; 
        
        merge_sort(arr, low, mid); 
        merge_sort(arr, mid, high); 
        
        int[] temp = new int[N];
        int i = low, j = mid;
        for (int k = 0; k < N; k++) 
        {
            if (i == mid)  
                temp[k] = arr[j++];
            else if (j == high) 
                temp[k] = arr[i++];
            else if (arr[j]<arr[i]) 
                temp[k] = arr[j++];
            else 
                temp[k] = arr[i++];
        }    
        for (int k = 0; k < N; k++) 
            arr[low + k] = temp[k];         
    }
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
     
System.out.print("\n\n");
System.out.print("===== Merge Sort in Java ====");
System.out.print("\n\n");
System.out.print("===== Written By: Mr. Jake R. Pomperada =====");;
System.out.print("\n\n");
System.out.print("How many items? : ");
        int num = input.nextInt();
        int numbers[] = new int[num];

System.out.println();
        for (int i = 0; i < num; i++) {
            System.out.print ("Give value in item no. " + (i+1) + " : ");
            numbers[i] = input.nextInt();
        }

        System.out.print("\n\n");
System.out.print("Original Number Arrangements" );
System.out.print("\n\n");
        for (int temp : numbers){
        System.out.print(temp);
            System.out.print(", ");
        } 
        System.out.print("\n\n");
System.out.print("Sorted Number Arrangements" );
System.out.print("\n\n");
        
        
        merge_sort(numbers,0,num);
        for(int a:numbers){
            System.out.print(a);
            System.out.print(", ");
}
        input.close();

}

}


Quick Sort in Java Version 2

Here is the implementation of quick sort version 2 using Java as my programming language. Our program will ask the user how many items to be sorted and then it will ask the user to give a series of numbers and then it will be sorted using selection sort algorithm. I hope you will find my work useful. 


I am currently accepting programming work kindly contact me in the following email address for further details. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.






Sample Program Output


Program Listing

/**
 * 
 */
package quick_sort;

import java.util.Scanner;

/**
 * @author Jake R. Pomperada
 * Bacolod City, Negros Occidental, Philippines
 * September 13, 2017   Wednesday
*/


public class Quick_Sort_Demo {

/**
* @param args
*/
public static void Quick_Sort_All(int[] arr)
    {
        Quick_Sorting(arr, 0, arr.length - 1);
    }
    
    public static void Quick_Sorting(int arr[], int low, int high) 
    {
        int i = low, j = high;
        int temp;
        int pivot = arr[(low + high) / 2];

        
        while (i <= j) 
        {
            while (arr[i] < pivot)
                i++;
            while (arr[j] > pivot)
                j--;
            if (i <= j) 
            {
                /** swap **/
                temp = arr[i];
                arr[i] = arr[j];
                arr[j] = temp;

                i++;
                j--;
            }
        }

        
        if (low < j)
        Quick_Sorting(arr, low, j);
        
        if (i < high)
        Quick_Sorting(arr, i, high);
    }
public static void main(String[] args) {
// TODO Auto-generated method stub
       Scanner input = new Scanner(System.in);
      
System.out.print("\n\n");
System.out.print("===== Quick Sort in Java ====");
System.out.print("\n\n");
System.out.print("===== Written By: Mr. Jake R. Pomperada =====");;
System.out.print("\n\n");
System.out.print("How many items? : ");
        int num = input.nextInt();
        int numbers[] = new int[num];

System.out.println();
        for (int i = 0; i < num; i++) {
            System.out.print ("Give value in item no. " + (i+1) + " : ");
            numbers[i] = input.nextInt();
        }

        System.out.print("\n\n");
System.out.print("Original Number Arrangements" );
System.out.print("\n\n");
        for (int temp : numbers){
        System.out.print(temp);
            System.out.print(", ");
        } 
        System.out.print("\n\n");
System.out.print("Sorted Number Arrangements" );
System.out.print("\n\n");
        
        
        Quick_Sort_All(numbers);
        for(int a:numbers){
            System.out.print(a);
            System.out.print(", ");
}
        input.close();

}

}





Tuesday, September 12, 2017

Insertion Sort in Java

Here is the implementation of insertion sort using Java as my programming language. Our program will ask the user how many items to be sorted and then it will ask the user to give a series of numbers and then it will be sorted using selection sort algorithm. I hope you will find my work useful. 


I am currently accepting programming work kindly contact me in the following email address for further details. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.




Sample Program Output


Program Listing

Insertion_Sorting.java

/**
 * 
 */
package insertion_sort;

import java.util.Scanner;

/**
 * @author Jake R. Pomperada
 * Bacolod City, Negros Occidental, Philippines
 * September 12, 2017   Tuesday
*/

public class Insertion_Sorting {

/**
* @param args
*/
public static int[] Insertion_Sorting_Test(int[] input){
         
       int temp;
       for (int i = 1; i < input.length; i++) {
           for(int j = i ; j > 0 ; j--){
               if(input[j] < input[j-1]){
                   temp = input[j];
                   input[j] = input[j-1];
                   input[j-1] = temp;
               }
           }
       }
       return input;
   }
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
System.out.print("\n\n");
System.out.print("===== Insertion Sort in Java ====");
System.out.print("\n\n");
System.out.print("===== Written By: Mr. Jake R. Pomperada =====");;
System.out.print("\n\n");
System.out.print("How many items? : ");
        int num = input.nextInt();
        int numbers[] = new int[num];

System.out.println();
        for (int i = 0; i < num; i++) {
            System.out.print ("Give value in item no. " + (i+1) + " : ");
            numbers[i] = input.nextInt();
        }

        System.out.print("\n\n");
System.out.print("Original Number Arrangements" );
System.out.print("\n\n");
        for (int temp : numbers){
        System.out.print(temp);
            System.out.print(", ");
        } 
                System.out.print("\n\n");
System.out.print("Sorted Number Arrangements" );
System.out.print("\n\n");
        
        
        int[] process_array = Insertion_Sorting_Test(numbers);
        for(int a:process_array){
            System.out.print(a);
            System.out.print(", ");
}
        input.close();
}

}