Question: I have this function, but when I run my test cases it stops after the first one. It doesn't crash the program, it just stops
I have this function, but when I run my test cases it stops after the first one. It doesn't crash the program, it just stops displaying any tests after test which leads me to beleive I have an infinite loop of some sort. But I can't find it Any ideas?
template
void SinglyLinkedList::swapFifthAndSeventhNodes
if thiscount
return; There are fewer than elements in the list, so no need to perform the swap
Node current thishead;
Node previous nullptr;
Traverse to the fifth node
for int i ; i ; i
previous current;
current currentlink;
Save pointers to the fifth and seventh nodes
Node fifthNode current;
Node seventhNode fifthNodelinklinklink;
Save pointers to the nodes next to fifth and seventh nodes
Node fifthNext fifthNodelink;
Node seventhNext seventhNodelink;
Rearrange the pointers
if previous
previouslink seventhNode;
else
thishead seventhNode;
fifthNodelink seventhNext;
seventhNodelink fifthNext;
Update tail pointer if necessary
if seventhNode thistail
thistail fifthNode;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
