Can any one tell me what I am doing wrong. I am sorting a single linked list.
void ll::sort()
{
for(int i=0;i<size-1;i++)
{node *cptr = fptr;
for(int j= 0;j<size-1;j++)
{
if((cptr->no) > (cptr->nxt->no))
{
if(cptr == fptr)
{ node *c2ptr = cptr->nxt;
cptr->nxt=c2ptr->nxt;
c2ptr->nxt=cptr;
fptr = c2ptr;
}
else
{
node *c2ptr = cptr->nxt;
node *tptr = fptr;
while(tptr->nxt!=cptr)
{ tptr=tptr->nxt;}
cptr->nxt=c2ptr->nxt;
c2ptr->nxt=cptr;
tptr->nxt=c2ptr;
}
}
cptr=cptr->nxt;
}
}
}