This is a discussion on Explain Reverse a linked list. within the C and C++ Programming forums, part of the Software Development category; Hi, Any one Explain. Thanks, Sundar Raja...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| This function reverses a singly linked list by walking the list and changing pointers. Each element in the list is an instance of a class ListNode. The list itself is an instance of a class List. ListNode has a next member that points to the next element on the list. The final element on the list has a next pointer equal to null. writen a function that can reverse a linked-list? void reverselist(void) { if(head==0) return; if(head->next==0) return; if(head->next==tail) { head->next = 0; tail->next = head; } else { node* pre = head; node* cur = head->next; node* curnext = cur->next; head->next = 0; cur->next = head; for(; curnext!=0; ) { cur->next = pre; pre = cur; cur = curnext; curnext = curnext->next; } curnext->next = cur; } } |
![]() |
| Thread Tools | |
| Display Modes | |
| |
LinkBacks (?)
LinkBack to this Thread: http://www.discussweb.com/c-c-programming/2410-explain-reverse-linked-list.html | |||
| Posted By | For | Type | Date |
| Explain Reverse a linked list. | Web Hosting | This thread | Refback | 03-06-2008 04:52 AM |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Reverse GeoCode | kingmaker | ASP and ASP.NET Programming | 3 | 12-11-2007 09:11 PM |
| What is a Linked Server in sql server 2005? | Archer | Database Support | 2 | 08-14-2007 04:24 AM |
| What pointer type is used to implement the heterogeneous linked list in C? | sundarraja | C and C++ Programming | 1 | 08-02-2007 11:16 PM |
| list box | nssukumar | Flash Actionscript Programming | 0 | 07-10-2007 06:34 AM |
| Does anyone else have a Life To Do List? | cocowgirl29 | The Lounge | 5 | 04-05-2007 06:58 AM |