Showing posts with label Heap Sort. Show all posts
Showing posts with label Heap Sort. Show all posts

Friday, April 15, 2011

Heap Sort


import java.util.Scanner;
class HeapSort
{
    static void Display(int a[], int n)
    {
        int i;
        for(i=0;i<n;i++)
            System.out.print("   "+a[i]);
        System.out.println("\n---------------------------------");
    }

    static void Heap(int x[],int n)
    {
        int i,elt,s,f,ivalue,pass=1;
        for(i=1;i<n;i++)
        {
            elt=x[i];
            s=i;
            f=(s-1)/2;
            while((s>0)&&(x[f]<elt))
            {
                x[s]=x[f];
                s=f;
                f=(s-1)/2;
            }
            x[s]=elt;