I need to reverse the items in a link list " List". The items have been inserted in ascending order and I need to change the actual order of the list from ascending to descending.
You can change the order by creating a pointer to the beginning (pFirst) and a pointer to the end of the list (pLast). Now use a local variable (temp) to change values like this:
temp = *pFirst;
*pFirst = *pLast;
*pLast = temp;
Then increment the first en decrement the last pointer:
pFirst++;
pLast--;
You can put this in a loop, because you know the number of items in the list and you should continue until pFirst >= pLast.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.