Doubt in code,coded string is different

when i am running this code on my laptop, the coded string is coming different but the final output is coming correct. I have written correct code.

please,someone answer…

@apoorvsingh27
send me your code i will check.

client: https://ide.codingblocks.com/s/238008

@apoorvsingh27
you code is absolutely correct but the variation in coded string is because when we have frequency of two or more characters same like in this case a,b,c have same frequency you dont know which node will come out of the minheap first that why you output is different.

in order to resolve this you can modify you compareTo function like this
@Override
public int compareTo(Node o) {
// comparing two nodes on the basis of cost
return (this.cost == o.cost)?this.data-o.data:this.cost-o.cost;
}

you will get the desired result from this.
Hepe it helps you . :grin:

if you still have any doubt feel free to ask otherwise mark this doubt as resolved in my doubt section and rate me as well :blush:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.