plz can any1 chk my program for errors

public class MinHeap{
    private int size=100;
    private int list[]=new int[size];
    private int currentSize=0;


    public boolean isFull(){
        if(currentSize==size)
            return true;
        return false;
    }

    public boolean isEmpty(){
        if(currentSize==0)
            return true;
        return false;
    }

    public void insert(int val){
        int current,parent,temp;
        if(isFull())
            System.out.println("Heap is full");
        else{
            list[++currentSize]=val;
            current=currentSize;
            parent=current/2;
            while(parent>0 && list[parent]>list[current]){
                temp=list[current];
                list[current]=list[parent];
                list[parent]=temp;
                current=parent;

                parent=parent/2;
            }

        }
    }

    public void displayList(){
        for(int i=1;i<=currentSize;i++){
                 System.out.println(list[i]);
            }
    }

public void heapSort(){
    int i,temp,j,rchild,lchild;
    i=currentSize;
    while(i>0){
        if(i==2&& list[2]<list[1])
            break;

        temp=list[1];
        list[1]=list[i];
        list[i]=temp;
        i=i-1;
        j=1;
        while(j<i){
            lchild=2*j;
            rchild=2*j+1;
                
                if(list[j]>list[lchild] && list[lchild]<list[rchild]&& lchild<i){
                    temp=list[j];
                    list[j]=list[lchild];
                    list[lchild]=temp;
                    j=lchild;
                }    
                else {

                    if(list[j]>list[rchild] && list[rchild]<list[lchild]&& rchild<i){
                        temp=list[j];
                        list[j]=list[rchild];
                        list[rchild]=temp;
                        j=rchild;
                
                    }
                    else
                        break;
                }
        }
    }
}

    public static void main(String[] as){
        MinHeap mylist=new MinHeap();
mylist.insert(23);
mylist.insert(67);
mylist.insert(93);
mylist.insert(5);
mylist.insert(78);
mylist.insert(96);
mylist.insert(47);
mylist.insert(22);
mylist.displayList();
mylist.heapSort();
System.out.println("After sorting");
mylist.displayList();
}

}
arkoenig commented: This isn't even a C++ program! +0
引领3妓生活 commented: 去 +0

Recommended Answers

All 6 Replies

I charge $25/hr to check for errors.

I charge $25/hr to check for errors.

Only $25/hr? Bummer, I guess I'm going to have to cut my rates... :P

No, no. Prices are relative to your knowledge on the subject, right? No need to lower your prices.

Wouldn't you think that when someone posts a program in a C++ forum and asks for help, the program would actually be a C++ program?

commented: You're tight, it does look more like Java doesn't it... +5

You're right, it does look more like Java doesn't it...

I saw the OP's comment and didn't even bother looking at the code. :)

Yeah, the main error here is that it's in Java. Your C++ compiler's going to really complain about that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.