30
Mar
Detecting broken links in double linked list
Related Blog Items
- Double Linked List With Out Using Special Head or Tail Node
- Circular Doubly Linked List With Out Using Special Head or Tail Node
- Reversing a double linked list
- Detecting a loop in single linked list
- Linked Lists
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
int detectbrokenlist(Node *n) { int brokenlinks = 0; Node *tmp = n; Node* after = n->next; Node* before = n->prev; //detect abnormalities in the list (broken links) after n (if any) while(after && tmp) { if ((after->prev != tmp) || (tmp->next != after)) { brokenlinks++; } after = after->next; tmp = tmp->next; } //detect abnormalities in the list (broken links) before n (if any) tmp = n; while(before && tmp) { if ((before->next != tmp) || (tmp->prev != before)) { brokenlinks++; } before = before->prev; tmp = tmp->prev; } return brokenlinks; }
any suggestions?
Popularity: 15%
You need to log on to convert this article into PDF
Related Blog Items - Double Linked List With Out Using Special Head or Tail Node
- Circular Doubly Linked List With Out Using Special Head or Tail Node
- Reversing a double linked list
- Detecting a loop in single linked list
- Linked Lists
Related Blog Items
- Double Linked List With Out Using Special Head or Tail Node
- Circular Doubly Linked List With Out Using Special Head or Tail Node
- Reversing a double linked list
- Detecting a loop in single linked list
- Linked Lists
[…] read more | digg story Written by ponnada - Visit Website Bookmark to: (is this useful? Please rate this post) Loading … This post was read:1 times […]
March 30th, 2007 at 10:02 pm
good one, I don’t think it returns correct number of broken links, after finding a broken link, alog is not dealing moving of pointer safely, however with algo we should be able to find atmost 2 broken links correctly
December 24th, 2007 at 1:55 pm