Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: Beginner
Mar 13, 1998

C++ Linked list

Question:
How would you reverse a linked list? Have looked in books at school library, and in tutorial. Hope you can point me in the right direction. Thank you for your time.

Answer:
The only way to directly traverse a linked list in reverse is to have the links arranged this way. Normally, this involves a doubly linked list. While a simple linked list only contains a pointer to the next node, a doubly linked list contains both a pointer to the next node and to the previous node. A doubly linked list also requires a Tail pointer that points to the last node in the list. This way, you can traverse the list from either the start or the end. Although doubly linked lists require a little more work to insert and delete nodes, they are very common when that degree of flexibility is required.

DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date