•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 402,507 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,859 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
void rev(node *h,node *myparentaddr) { if(h->next!=NULL) { rev(h->next,h); tail=h; } else head=h; h->next=myparentaddr; } call it in main by rev(head,NULL);
Comments (Newest First)
jessel | Newbie Poster | Feb 26th, 2008
•
•
•
•
hello do you have a program in c that deals in linked list?
please help me
please help me
farwa | Newbie Poster | Feb 7th, 2008
•
•
•
•
hello every one i m new to c language can any one help me in typing a marksheet in c.
Duoas | Posting Virtuoso | Nov 9th, 2007
•
•
•
•
Nice, but it fails on three counts:
1. It doesn't return the new head of the list.
2. It fails if h is NULL.
3. It fails on really big lists (stack overflow).
Here's an iterative solution you might enjoy.
Call it thus:
Enjoy!
1. It doesn't return the new head of the list.
2. It fails if h is NULL.
3. It fails on really big lists (stack overflow).
Here's an iterative solution you might enjoy.
C Syntax (Toggle Plain Text)
/* Reverse a singly linked list without recursion. The argument may be NULL. Returns the new head of the list. Runs in linear time and with constant memory usage. */ node *rev( node *head ) { node *next; node *curr = head; node *prev = NULL; while (curr != NULL) { next = curr->next; curr->next = prev; prev = curr; curr = next; } return prev; }
head = rev( head );Enjoy!
jai_steave | Newbie Poster | Oct 18th, 2007
Post Comment
•
•
•
•
DaniWeb Marketplace (Sponsored Links)