You start printing from last->next
but the condition in the while breaks when q==last
. So you are not printing the last
node.
If else
part is going to be executed, then you know there's at least one node in the list. So you can change the else part to:
q=last->next;
do{
printf("%d\n",q->data);
q=q->next;
}while(q!=last->next);