Sunday 27 April 2014

Sorting programming in java


I am here telling you about Java programming.I am telling here about sorting programming as given below:

Program 1: Bubble Sort
Use your package;
Import Scanner 

class BubbleSort {
  public static void main(String []args) {
    int n, i, j, temp;
    Scanner in = new Scanner(System.in);

    System.out.println("Input number of integers to Bubble sort");
    n = in.nextInt();

    int array[] = new int[n];

    System.out.println("Enter array " + n + " integers");

    for (i = 0; i < n; i++)
      array[i] = in.nextInt();// for array input by user.

    for (i = 0; i < ( n - 1 ); i++) {
      for (j = 0; j < n - i - 1; j++) {
        if (array[j] > array[j+1]) 
        {
          temp       = array[j];
          array[j]   = array[j+1];
          array[j+1] = temp;
        }
      }
    }

    System.out.println("Sorted list of numbers");

    for (i = 0; i < n; i++)
      System.out.println(array[i]);
  }
}

Program 1: Insertion Sort
Use your package;
Import Scanner 

public class MyInsertionSort {

    public static void main(String[] args) {
         
        int[] arr = {9,8,18,5,96,45,2,74 };
        insertionSort(arr);
    }
     
    private static void printNumbers(int[] arr) {
         
        for (int i = 0; i < input.length; i++) {
            System.out.print(arr[i] + ", ");
        }
        System.out.println("\n");
    }

    public static void insertionSort(int array[]) {
        int n = array.length;
        for (int j = 1; j < n; j++) {
            int key = array[j];
            int i = j-1;
            while ( (i > -1) && ( array [i] > key ) ) {
                array [i+1] = array [i];
                i--;
            }
            array[i+1] = key;
            printNumbers(array);
        }
    }
}


Program 3: Selection Sort
Use your package;
Import Scanner 

Selection:
public class SelectionSort {

    public static int[] SSelectionSort(int[] arr){
         
        for (int i = 0; i < arr.length - 1; i++)
        {
            int index = i;
            for (int j = i + 1; j < arr.length; j++)
                if (arr[j] < arr[index])
                    index = j;
      
            int temp = arr[index]; 
            arr[index] = arr[i];
            arr[i] = temp;
        }
        return arr;
    }
     
    public static void main(String a[]){
         
        int[] arr1 = {12,5,98,48,78,96,6,2};
        int[] arr2 = SSelectionSort(arr1);
        for(int i:arr2){
            System.out.print(i);
            System.out.print(", ");
        }
    }
}



Program 4: Quick Sort
Use your package;
Import Scanner 

public class QuickSort {
     
    private int array[];
    private int length;

    public void sort(int[] inputArr) {
         
        if (inputArr == null || inputArr.length == 0) {
            return;
        }
        this.array = inputArr;
        length = inputArr.length;
        quickSort(0, length - 1);
    }

    private void quickSort(int lowerIndex, int higherIndex) {
         
        int i = lowerIndex;
        int j = higherIndex;
        int pivot = array[lowerIndex+(higherIndex-lowerIndex)/2];
       
        while (i <= j) {
           
            while (array[i] < pivot) {
                i++;
            }
            while (array[j] > pivot) {
                j--;
            }
            if (i <= j) {
                exchangeNumbers(i, j);
                //move index to next position on both sides
                i++;
                j--;
            }
        }
        if (lowerIndex < j)
            quickSort(lowerIndex, j);
        if (i < higherIndex)
            quickSort(i, higherIndex);
    }

    private void exchangeNumbers(int i, int j) {
        int temp = array[i];
        array[i] = array[j];
        array[j] = temp;
    }
     
    public static void main(String a[]){
         
       QuickSort sorter = new QuickSort();
        int[] input = {87,74,47,85,76,5,15,2};
        sorter.sort(input);
        for(int i:input){
            System.out.print(i);
            System.out.print(" ");
        }
    }

}



Program 4: Merg Sort
Use your package;
Import Scanner 

public class MergeSort {
     
    private int[] array;
    private int[] tempArr;
    private int length;

    public static void main(String a[]){
         
        int[] inputArr = {3,9,8,2,4,7,78,62};
        MergeSort mm = new MergeSort();
        mm.sort(inputArr);
        for(int i:inputArr){
            System.out.print(i);
            System.out.print(" ");
        }
    }
     
    public void sort(int inputArr[]) {
        this.array = inputArr;
        this.length = inputArr.length;
        this.tempArr = new int[length];
        doMergeSort(0, length - 1);
    }

    private void doMergeSort(int lowerIndex, int higherIndex) {
         
        if (lowerIndex < higherIndex) {
            int middle = lowerIndex + (higherIndex - lowerIndex) / 2;
            
            doMergeSort(lowerIndex, middle);
        
            doMergeSort(middle + 1, higherIndex);
            
            mergeParts(lowerIndex, middle, higherIndex);
        }
    }

    private void mergeParts(int lowerIndex, int middle, int higherIndex) {

        for (int i = lowerIndex; i <= higherIndex; i++) {
            tempArr[i] = array[i];
        }
        int i = lowerIndex;
        int j = middle + 1;
        int k = lowerIndex;
        while (i <= middle && j <= higherIndex) {
            if (tempArr[i] <= tempArr[j]) {
                array[k] = tempArr[i];
                i++;
            } else {
                array[k] = tempArr[j];
                j++;
            }
            k++;
        }
        while (i <= middle) {
            array[k] = tempArr[i];
            k++;
            i++;
        }

    }
}

Wednesday 23 April 2014

Call India, Cheapest Call to India and Send Text Message to India form Anywhere: Calling card the necessity

Call India, Cheapest Call to India and Send Text Message to India form Anywhere: Calling card the necessity: Traditionally, the communication used to occur by the letters. People used to visit the government post offices to buy the foreign inland ...

Calling card the necessity

Traditionally, the communication used to occur by the letters. People used to visit the government post offices to buy the foreign inland letters. The letters used to reach the destinations within a fortnight and sometime within a month. Such response used to be considered as the quickest form of transmitting messages from one end to another. The long waiting and the emotional disturbances have destroyed several lives at the time. Parents used to object any oversea opportunities which the new generation like to avail. Similarly, the young generation also used to refuse the opportunities due to fear of making their parents alone due to long waited communications. But today, the calling cards have completely changed the system.

Always in contact


The communication to the foreign country is now a cake walk. Anybody can call and stay connected for longer and longest period of time. The calling cards, VoIP and internet messaging have enabled users call at distance location without thinking about the geographical distance and differences. Forget parents and the child relationships which used to afraid of the distances. Today, business enterprises are using the technologies mentioned above to keep their business and clients stay in touch on the real-time basis. The globalization has occurred just due to the stability and the solution that calling cards and other provided in the world of business. Now, considering the relationships, parents and families and friends are now happy as they can video chat with the close ones who are far ones now.

Vision


The calling cards are not the just solution provided to the world of communication. The communication is going to the widespread fast and beyond the technological era. For example, people using call India for staying in touch with the people, will avail much enhanced solution in the future at cheaper price. The companies' expansions and the new users availability is going to bring astonishing solution in the arena of long distance calls. Forget the past, the present and the future of the technology is getting enhanced and much futuristic for the users and growing markets.