I was writing function for the following : /* print list in pair of two : eg: list : 1 2 3 4 5 6 pair list: 2 1 4 3 6 5*/.
printPair(){
bool flag = 1;
node *temp = new node();
node *temp2 = new node();
temp2 = NULL;
if(!head)
{
printf("Empty List!!");
return 0;
}
temp = head;
while(!temp && !temp->next) //Error here 1. {
if(!temp2) //Error here 2.
temp2->next->next = temp->next;
temp2 = temp->next;
temp->next = temp->next->next;
temp2->next = temp;
if(flag)
{
head = temp2;
flag = 0;
}
temp = temp->next;
}
/* it works fine if replaced with : 1.while(temp !=NULL && temp->next !=NULL) 2. if(temp2 != NULL) */ So how is this ! is different from !=
Aucun commentaire:
Enregistrer un commentaire