sorting in doubly link list.my code is not working properly.its does sort for 1 or 2 numbers but thn it crashed.

void sorting(comp *&h, comp *&t ){
if (h==NULL){
cout<<"oppsssss there is no numbe*r to short";}
else{
comp *c; int n=0;
c=h;
// while(c!=NULL){
// n++;
// c=c->next;
////}
//for(int i=1;i<n;i++)
while(c!=NULL){
if (c->d.x.real()>c->next->d.x.real()){
swap(c->d.x,c->next->d.x);
}
cout<<c->d.x;
c=c->next;
}

}
}};



You use c->next without checking if it's null.
Topic archived. No new replies allowed.