insertion sort using linked list

can anyone tell wants wrong with my insertion sort ..aplyinh on linked list

void Insertion_Sort()
{int count;
node *p;
p=HEAD;
while(p!=NULL)
{
count++;
p=p->NEXT;
}
node *i,*j,*temp;
i=i->NEXT;
j=HEAD;

for(int k=1;k<count;k++)
{
temp->info=i->info;
for(int l=k;k>0 && (temp->info < j->info);k--)
p->info=j->info;
p->info=temp->info;
}
}
Right off the bat:
1
2
node *i,*j,*temp;
i=i->NEXT;

You declare i as a pointer to a node (But haven't actually assigned memory for it, so it's now pointing to some garbage location), but then you immediately try to point it to its own NEXT pointer.

Again, with *temp, you need to create the object before you can assign it values.
 
temp->info=i->info;
can you rectify the code..so that i can understand better
Topic archived. No new replies allowed.