cpppro

Archive for March, 2007|Monthly archive page

Reversing a double linked list

In Algorithms, C Tidbits, Data Structures in C/C++ on March 30, 2007 at 5:43 pm

refer double linked list post for information about double linked list. Here in this post we will be discussing about reversing a double linked list.

Here is the pictorial representation of our algo…
reversing double linked list

in our routine we will swap our next, prev pointers of nodes to reverse the double linked list… this routine capable of reversing entire list for given any node in the double linked list.

The below routine takes input as any node in double linked list and reverse the entire double linked list and returns same node pointer.

please refer http://www.refcode.net/2013/02/reversing-double-linked-list.html

Detecting broken links in double linked list

In C Tidbits, Data Structures in C/C++ on March 30, 2007 at 4:12 pm

Here is a routine which does find out broken links in double linked list, wondering what is a broken link…

 

here is the code snippet for detecting broken links in double linked list…

for complete operations (all operations) on double linked list, visit earlier post

please refer http://www.refcode.net/2013/02/detecting-broken-links-in-double-linked.html

Reversing a single linked list using stack

In Algorithms, C Tidbits, Data Structures in C/C++ on March 30, 2007 at 3:40 pm

Here is the routine for reversing single linked list using a stack, for reversing linked list using pointers, see the earlier post. For reversing linked list recursively visit this post. This routine takes a single linked list as argument and reverse it and returns back the head node to the reversed list.

please refer http://www.refcode.net/2013/02/reversing-single-linked-list-using-stack.html

Reversing single linked list recursively

In Algorithms, C Tidbits, Data Structures in C/C++ on March 30, 2007 at 3:30 pm

Here is the routine for reversing single linked list recursively, for reversing iteratively see the earlier post . For reversing circular single linked list visit this post. This routine takes a single linked list as argument and reverse it and returns back the head node to the reversed list.

 

please refer http://www.refcode.net/2013/02/reversing-single-linked-list-recursively.html

Reversing a circular single linked list using pointers

In C Tidbits, Data Structures in C/C++ on March 10, 2007 at 4:50 pm

Reversing a single linked list is explained in this post

this post deals with reversing circular single linked list, which is not much different from what we did there except the last reversed node points the head node, then we change the head node to point to reversed linked list….

You might be thinking why do we need to reverse a circular linked list when the list is circular, but as the list is single linked list here we are going to reverse the direction of the list.

here is the routine which reverses circular list….

please refer http://www.refcode.net/2013/02/reversing-circular-single-linked-list.html