Search

Sponsored Links

Meta

Categories

Archives

Recent Posts

RSS Feeds

30
Mar

Detecting broken links in double linked list

Related Blog Items

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

 

double linked list - broken links

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

2 Comments

Leave a comment

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-spam image