Friday, August 29, 2008

Finding an item from a Singly Linked List

Operations on any but the first element of a linked list require traversal of some elements of the list, and you must always check for the end of the list.

ListElement Find( ListElement head, int data )

{

while( head != NULL && head.data != data )

{

head = head.next;

}

return head;

}

No comments: