hey starting data structers through pointers , i don't know how to reverse a singly linklist?
pls help
sparsh610 0 Newbie Poster
Recommended Answers
Jump to PostHave you learned recursion? I think you could reverse an empty list quite easily wouldn't you? You just figure out how to reverse the list consisting on first node and rest of list reversed.
Non-recursive reversing requires just that you remember the previous node and consider carefully corner cases like …
Jump to PostOne basic algorithm is basically just reversing the next-pointer between two adjacent nodes while traversing the list, and at the end, you swap the head and tail pointers. To do this, you need to keep three node pointers, for three consecutive nodes (the last may be NULL). If you have …
Jump to Postbut what if question arise to reverse the link list without using pointers?
Is it still a singly linked list? Are you allowed to create another variable or data structure to hold the reversed data? Is this a hypothetical question? ;)
Jump to Postbut what if question arise to reverse the link list without using pointers?
Well, a linked-list is just a chain of nodes pointing to each other. You can't really do anything with a linked-list without using pointers. To start, you have to use the "head" pointer, so that's …
Jump to PostI think he meant without pointer surgery, such as if you traverse and swap the data.
All 18 Replies
firdousahmad -1 Junior Poster in Training
Trentacle commented: don't use sms-speak +0
sparsh610 0 Newbie Poster
TrustyTony 888 ex-Moderator Team Colleague Featured Poster
L7Sqr commented: Recursion is certainly the way to go +8
Sokurenko 42 Junior Poster
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster
firdousahmad -1 Junior Poster in Training
sparsh610 0 Newbie Poster
deceptikon 1,790 Code Sniper Team Colleague Featured Poster
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster
deceptikon 1,790 Code Sniper Team Colleague Featured Poster
sparsh610 0 Newbie Poster
deceptikon 1,790 Code Sniper Team Colleague Featured Poster
sparsh610 0 Newbie Poster
firdousahmad -1 Junior Poster in Training
Sokurenko 42 Junior Poster
paramv 0 Newbie Poster
Sokurenko 42 Junior Poster
sethlahaul 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.