Java Tutorial

 
 
 
 
import java.io.*;

class sort
{
      String str;
      int size,sortArr[];

      public void getdata()
      {
             System.out.print(\"Enter how many data you want to enter : \");
             System.out.flush();
             try{
                 BufferedReader obj=new BufferedReader(new 

InputStreamReader(System.in));
                 str=obj.readLine();
                 size=Integer.parseInt(str);
                 sortArr=new int[size];
                 for(int i=0;i<size;i++)
                   {
                       System.out.print(\"Enter element at \"+(i+1)+\"th 

position  :  \");
                       System.out.flush();
                       str=obj.readLine();
                       sortArr[i]=Integer.parseInt(str);
                   }
                }
            catch(Exception e)  {}
            QuickSort(sortArr,0,size-1);
      }

      public void  QuickSort(int sortArr[],int lb,int ub)
      {       
                int i,j,key,flag=0,temp;
                if(lb<ub)
                {
                   i=lb;
                   j=ub+1;
                   key=k[i];
                   while(flag!=1)
                     {
                         i++;
                         while(k[i]<key)
                              i++;
                        j--;
                        while(k[j]>key)
                              j--;
                        if(i<j)
                          {
                              temp=k[i];
                              k[i]=k[j];
                              k[j]=temp;
                           }
                        else
                          {
                             flag=1;
                             temp=k[lb];
                             k[lb]=k[j];
                             k[j]=temp;
                          }
                    }
                QuickSort(sortArr,lb,j-1)
                QuickSort(sortArr,j+1,ub);
            }
        }

    public void display()
    {
         System.out.println(\"\\nAfter Sorting\");
         for(int i=0;i<size;i++)
              System.out.println(sortArr[i]);
    }
}


class QuickSort 
{
    public static void main(String args[]) 
    {
          sort ob1=new sort();
           System.out.println(\"=====QUICK SORT=====\\n\");
            ob1.getdata();
            ob1.display();
    }
}

    Related Post:
  1. Program to show the comparing of Strings for equality

  2. Program which calls the method sort(int []a) which throws the Exception ArithmeticException, NullPointerException, ArrayIndexOutOfBoundsException

  3. Program to show the use of Break Statement

  4. An applet program to display barchart of given data

  5. Program to show the use of Bitwise Operator (|) OR

  6. Program to show an example of Polymorphism

  7. An applet program that creates string dynamically and displays it

  8. Program to change characters in a StringBuffer objects and to reverse its contents

  9. Write a program for restaurant

  10. Develop a simple calculator with addition, subtraction, multiplication and division capabilities, data collection from client side, executed on server

  11. Given a list of marks ranging form 0 to 100, write a program to compute and print the number of students marks

  12. An applet program to perform quick sort

  13. Program that takes a long sentence and a character from the client and count the occurrence of the character in the sentence at the server side

  14. Program to sort the contents of an array using Bubble Sort

  15. Program to show the use of Nested If-Else Statements

  16. Program to show some properties of StringBuffer object

  17. Program to show an example of using Abstract Class and Abstract Method

  18. RMI based application for login validation based on data saved in text file stored on the server and will display appropriate message to the client..

  19. Program that reads and writes random access file

  20. Program to show an example of Copying i.e. Clonning Objects

 
 
Didn't find what you were looking for? Find more on An applet program to perform quick sort