| | |
reverse linked list
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Nov 2007
Posts: 146
Reputation:
Solved Threads: 0
hello
i want to build a function which receives a pointer to a head of linked list
reverses the order of the list and returns a pointer to the new head.
my list is defined like this :
my fucction is :
at first when i print the list it is ok
when i try to print the list after the function it shows nothing
please advice.
i want to build a function which receives a pointer to a head of linked list
reverses the order of the list and returns a pointer to the new head.
my list is defined like this :
C Syntax (Toggle Plain Text)
typedef struct item { int key ; struct item *next ; } item ;
my fucction is :
C Syntax (Toggle Plain Text)
void swapitem ( item *a ) { (a -> next) -> next = a ; a -> next = NULL ; } // end swapitem item** revList ( item *head ) { item **p ; if ( !head -> next ) { **p = *head ; return p ; } else { revList (head->next) ; swapitem (head) ; return p ; } } // end revList
at first when i print the list it is ok
when i try to print the list after the function it shows nothing
please advice.
I always take it a step farther and just tell people to forget the code. Get out the paper and crayons first, draw what must happen, then write the code to do exactly that.
Disentangling new programmers from bad code is more difficult and confusing than just going through the steps of writing the code correctly to begin with...
Disentangling new programmers from bad code is more difficult and confusing than just going through the steps of writing the code correctly to begin with...
>Disentangling new programmers from bad code is more
>difficult and confusing than just going through the steps
>of writing the code correctly to begin with...
Writing code correctly is all well and good, but learning to debug broken code is just as important (if not more so).
>difficult and confusing than just going through the steps
>of writing the code correctly to begin with...
Writing code correctly is all well and good, but learning to debug broken code is just as important (if not more so).
New members chased away this month: 5
•
•
Join Date: Nov 2007
Posts: 146
Reputation:
Solved Threads: 0
ok i did it all i had to do is turn my pointer static
thanks everyone for the help
C Syntax (Toggle Plain Text)
item *revList ( item *head ) { static item* p ; if ( !head -> next ) { p = head ; return head ; } revList (head->next) ; swapitem (head) ; return p ; } // end revList
thanks everyone for the help
![]() |
Similar Threads
- Removing an item from head of linked list (C)
- Doubly Linked List Problem (C++)
- how do you reverse a linked list using recursion and return it as a string? (Java)
- linked lists (C)
Other Threads in the C Forum
- Previous Thread: Adding character to inputbuffer
- Next Thread: Pushbutton
Views: 2203 | Replies: 5
| Thread Tools | Search this Thread |
Tag cloud for C
#include * .net append array arrays asterisks binarysearch calculate changingto char character cm command copyimagefile cprogramme creafecopyofanytypeoffileinc database directory dynamic execv feet fgets file fork forloop framework function functions givemetehcodez grade graphics gtkwinlinux hacking histogram homework include incrementoperators input intmain() iso kernel keyboard km lazy license linked linkedlist linux list lists locate logical_drives looping loopinsideloop. lowest matrix microsoft mqqueue mysql number oddnumber odf opensource overwrite owf pdf performance pointer pointers posix probleminc process program programming radix recursion recv recvblocked research reversing scanf scripting segmentationfault sequential socket spoonfeeding standard string student systemcall testing threads turboc unix user variable wab whythiscodecausesegmentationfault windowsapi






