Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

link list

Status
Not open for further replies.

Softy

Programmer
Joined
Apr 18, 2001
Messages
1
Location
AU
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.

Ivar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top