Wednesday 28 June 2017

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

1) Keep track of how many objects are pointing to a object using reference counts if required.

2)Use a good debugger to see how the datastructures are getting corrupted and trace down the problem like Purfiy, gdb..etc

3) Its a good idea to check the addNode() and the deleteNode() routines and test them for all types of scenarios. This should include tests for inserting/deleting nodes at the front/middle/end of the linked list, working with an empty linked list, running out of memory when using malloc() when allocating memory for new nodes, writing through NULL pointers...etc.

4)Each node can have an extra field associated with it. This field indicates the number of nodes after this node in the linked list. This extra field needs to be kept up-to-date when we inserte or delete nodes in the linked list.

No comments:

Post a Comment