This site requires JavaScript.
It looks like you have disabled JavaScript in your browser or are using a browser that does not support JavaScript.
Please enable it or try another browser.

Ad Blocker Detected

You must disable your ad-blocking software for our web site in your browser to use this site.
You don't have to turn off the ad blocker entirely; just disable ad blocking for codestepbystep.com, then refresh this page to continue.

It is easy to disable a tool like AdBlock for just one site while leaving it enabled for other sites.
Just click the "stop sign" icon in the top-right of your browser, then un-check the "Enabled for this site" checkbox.
If your UI doesn't match the screenshot below, you may want to Google for how to add a "whitelisted domain" to your ad blocker to allow ads from codestepbystep.com to be shown.

Thank you for your understanding and helping us to keep this service free of cost for all students to use.

Note: If you are seeing this message but aren't running an ad blocker or have disabled your ad blocker:

Try clearing your browser history and refreshing the page.

Make sure you don't have any other ad-blocking software running outside of your browser, such as a HOSTS file or proxy.

If you are using a school computer network:
Many high schools have "proxy" software that blocks ads at the entire school level.
Your school's system administrator may need to add an exception for codestepbystep.com to allow these ads to get through.
You may need to copy/paste this information to your school's network administrator so that he/she can make appropriate changes to your network settings.

If you have questions or need any other assistance,
please Contact Us.

switchPairsOfPairs

Write a function named switchPairsOfPairs that rearranges a linked list of integers by switching the order of each two neighboring pairs of elements in the sequence.
Your function is passed a reference to a pointer to the front of the list as a parameter.
Suppose, for example, that a variable named list points to the front of a list storing the following values:

Notice that the pair (1, 2) has been switched with the pair (3, 4) and that the pair (5, 6) has been switched with the pair (7, 8).
This example purposely used sequential integers to make the rearrangement clear, but you should not expect that the list will store sequential integers.
It also might have extra values at the end that are not part of a group of four.
Such values should not be moved.
For example, if the list had stored this sequence of values:

{3, 8, 19, 42, 7, 26, 19, -8, 193, 204, 6, -4, 99, 2, 7}

Then a call on the function should modify the list to store the following.
Note that 99, 2, 7 at the end are not switched:

{19, 42, 3, 8, 19, -8, 7, 26, 6, -4, 193, 204, 99, 2, 7}

Your function should work properly for a list of any size.
Note: The goal of this problem is to modify the list by modifying pointers.
It might be easier to solve it in other ways, such as by changing nodes' data values or by rebuilding an entirely new list, but such tactics are forbidden.

Constraints:

Your code should run in no worse than O(N) time, where N is the length of the list.
Your code must make a single pass over the list (not multiple passes).

Note that the list has no "size" function, nor are you allowed to loop over the whole list to count its size.

Do not use any auxiliary data structures such as arrays, vectors, queues, strings, maps, sets, etc.

Do not modify the data field of any nodes; you must solve the problem by changing the links between nodes.

You may not construct new ListNode objects, though you may create as many ListNode* pointers as you like.

If you do not understand how to solve an exercise or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect tests, etc.), please