Question

Possible Duplicate:
Exception in thread “main” java.lang.NoSuchMethodError: main

My main syntax is correct. What else could be the problem?

public class BuildHeap
{       
  int a[]={1,2,6,3,5,1,7,8,4,9};

  public void build()
  {
      for(int i=5;i<=1;i--)
      {
         heapify(a,i);
      }
  }

  public void heapify(int a[],int i)
  { 
    System.out.print("hello");
    int j,temp,rchild,lchild;
    if(i<5)
     {
        if(2*i<5)
            lchild=a[(2*i)+1];
        if((2*i)+1<4)
            rchild=a[(2*i)+2];

        if(lchild>rchild)
            j=(2*i)+1;
        else
            j=(2*i)+2;

        if(a[i]<a[j])
         {
            temp=a[i];
            a[i]=a[j];
            a[j]=temp;
            heapify(a,j);

} } }

class Heap
{
    public static void main(String[] args) 
    {
        BuildHeap bh=new BuildHeap();
        bh.build();
        for(int i=0;i<10;i++)
            System.out.print(bh.a[i]+" ");
    }
}

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top