Thread: reverse doubly linked list

  1. #1
    Registered User
    Join Date
    Aug 2015
    Posts
    73

    reverse doubly linked list

    i want to reverse doubly linked list. this is the code i tried but its not working. it is printing only first value. i have passed first node to this function.

    Code:
    reverse(node *t)
    {
        while(t!=NULL) {
            temp=t->next;
            t->next=t->prev;
            t->prev=temp;
            t=t->prev;
        }
    }
    please help me and correct my code

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,596
    The whole point of a doubly linked list is to avoid the nonsense of list reversal.

    If you want to traverse it backwards, you just start at tail, and follow all the node->prev until you get to NULL.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with doubly linked List
    By plot in forum C Programming
    Replies: 6
    Last Post: 10-13-2013, 03:03 AM
  2. Help with my doubly linked list
    By evildotaing in forum C++ Programming
    Replies: 3
    Last Post: 11-29-2011, 11:47 AM
  3. Doubly linked list
    By msky in forum C Programming
    Replies: 0
    Last Post: 11-11-2011, 04:25 PM
  4. doubly linked list
    By bahareh in forum C++ Programming
    Replies: 7
    Last Post: 03-28-2007, 01:31 PM
  5. singly linked list to doubly linked list
    By t48j in forum C Programming
    Replies: 3
    Last Post: 03-23-2005, 06:37 PM

Tags for this Thread