Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
Thread Tools Search this Thread Rate Thread
Old 07-Apr-2008, 11:16
swedenguy swedenguy is offline
New Member
Join Date: Aug 2006
Posts: 8
swedenguy is on a distinguished road

How do I reverse a circular double linked list

Hi everyone!
I have a circular double linked list see
for a description of circular double linked list.
I want to reverse the list with a function called
void reverse(list_t** head ); or maybe void reverse(list_t** head, list_t* last);
where head is the first element and last is the last element.
My first implementation was to start from last element until i reach the first element and put those element in a new double linked list until. (every element is inserted last in the list)
However i changed the requirement for me and i do not want to have a new list to move element on it.
I want to use same list but i always succeed to loose reference to some element.
Therefore i hope that some of you can help me with that and i appreciate if somebody can help me with this ( it is enough with a pseudo code description)
To make it shorter i want to use same list and reverse it without using a temporary linked list
Thanks for all help
Old 15-Dec-2016, 03:52
fedemengo fedemengo is offline
New Member
Join Date: Dec 2016
Posts: 1
fedemengo is on a distinguished road

Re: how do i reverse a circular double linked list

You can do something like that

struct node {
int value;
struct node *next;
struct node *prev;

void reverse(struct node **s){
if(s != NULL && *s != NULL){
struct node *node = *s;
/* reverse the list */
do {
struct node *tmp = node->next;
node->next = node->prev;
node->prev = tmp;
node = tmp;
} while(node != *s);
/* update the pointer */
*s = (*s)->next;

That's it

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Str_Misaligned in Double Link List Peter_APIIT C Programming Language 1 29-Feb-2008 21:50
Airport Log program using 3D linked List : problem reading from file batrsau C Programming Language 11 29-Feb-2008 08:44
Double linked List & File System NatsoumiMaya C Programming Language 1 10-Feb-2008 09:23
Double output leanieleanz C++ Forum 1 11-Mar-2005 21:19

Network Sites: GIDNetwork · GIDApp · GIDBlog · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 18:35.

vBulletin, Copyright © 2000 - 2017, Jelsoft Enterprises Ltd.