Help me make this code more efficient.

Code:void llist::sort() { int val,val1; for(node *p = first, *p1, *pos; p->next != NULL; p = p->next) { val = p->info; pos = p; for(node *q = p; q->next != NULL; q = q->next) { val1 = (*(q->next)).info; if(val1 < val) { val = val1; pos = q; } } if(val != p->info) { node *temp = pos->next; if( temp!= NULL) pos->next = temp->next; else pos->next = NULL; if(pos != p) { temp->next = p->next; p->next = pos->next; pos->next = p; } else temp->next = p; if(p == first) first = temp; else p1->next = temp; p = temp; } p1 = p; } }