IT Community - Software Programming, Web Development and Technical Support

Explain Reverse a linked list.

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...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C and C++ Programming

Register FAQ Members List Calendar Mark Forums Read
  1 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 07-21-2007, 01:08 AM
sundarraja sundarraja is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Posts: 174
sundarraja is on a distinguished road
Question Explain Reverse a linked list.

Hi,

Any one Explain.

Thanks,
Sundar Raja
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-02-2007, 11:27 PM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 350
Venkat is on a distinguished road
Thumbs up Re: Explain Reverse a linked list.

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;
}
}
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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


All times are GMT -7. The time now is 08:53 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0