Given this link list opbitrsahopec when you run the program
Given this link list
op->bi->tr->s->a->ho->pec
when you run the program you get the output
s->pec->tr->op->ho->bi->a
Can you comment the code and explain it to me to help me interpret it and understand how that output is produced. The if, else statement in the middle of the body confuses me.
void SLL::MakeIt() {
last->next = first; //What is this line of code doing?
SNode *tmp = first;
int ct = 0;
int s2 = 0;
SNode *tmp2;
while(size > 0) {
if(ct == 2) {
if(s2 == 0) { //how is this if statemnet altering the liked list?
first = tmp->next;
tmp->next = tmp->next->next;
first->next = NULL;
tmp2 = first;
} //if
else { //how is this else statement altering the linked list?
tmp2->next = tmp->next;
tmp->next = tmp->next->next;
tmp2->next->next = NULL;
tmp2 = tmp2->next;
}//else
s2++;
ct = 0;
size--;
}//if
ct++;
tmp = tmp->next;
}//while
last = tmp2;
}
Solution
last->next = first;
first value is asigned to last>next node(added to list )
f(s2 == 0) { //how is this if statemnet altering the liked list?
first = tmp->next;
tmp->next = tmp->next->next;
first->next = NULL;
tmp2 = first;
} //if
meaninf of this check node is first node or not
in case first node then
swap the values form first to next fromat
if any doubts plz forward to me
thank you
the program will check size>0 or not
in case size =0 there is no swap because there is no link or elements
size>0
then check
perticular node is first node or not
its first node then exchange the values and reduce the list size


