top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How would you find out if one of the pointers in a linked list is corrupted or not?

+3 votes
866 views
How would you find out if one of the pointers in a linked list is corrupted or not?
posted Sep 24, 2014 by Aarti Jain

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
Is it a doubly link list...
No.. its a singly link list

2 Answers

+2 votes

If it is a doubly link list then at each node it should satisfy the condition pNode->Next->Prev == pNode

If it is a single link list then it is bit tricky may be you need to add an extra field with each node which will indicate number of nodes after this node in the linked list. This extra field needs to be kept up-to-date when we insert or delete nodes in the linked list. And for every node, pNode->field > pNode->Next->field. This may not be the best solution so waiting for others to suggest something better.

answer Sep 24, 2014 by Salil Agrawal
+2 votes
  1. See if the linked list is holding the data that you inserted into it, i.e (if you'd expect a pointer to be NULL, make sure it's NULL. if you'd expect a pointer to refer to an already existing object, verify that that object's address has that value, etc.)
  2. You can have an extra field as per the "Salil" has suggested, but it is difficult to manage if you are going to insert or delete at any position
  3. And you can use mprotect() (do a man of mprotect to see how to use) in linux, if we are passing the invalid address in mprotect(). you can check with this fucntion i.e
    the pointer is pointing to read only memory or write only memory or a not accessible memory etc
answer Sep 25, 2014 by Arshad Khan
Similar Questions
+2 votes

How to find the median of simple linked list and add a node after it? C program would be helpful?

+1 vote

What is the best logic or way to detected linked list has loop ?
And also what is the best way to find out that given linked list is circular ?

...