Thursday, November 19, 2009

Pseudocode for linked list?

A linked list pointed by H is given. Delete all the records with even indices (2, 4, 6,…)


from the list to create a second list pointed by H1.





Can anyone help me write a psedocode for this

Pseudocode for linked list?
Since you are to produce a second list, you just have to walk through the first list and copy every other element over.





Create new list.





H1 = NewList;





OldList.GetFirst() // item 1





Loop until done


{


link = OldList.GetNext() // even numbered link


NewList.AddLink(link); // add it to the new list


link = OldList.GetNext() // odd link, ignore


}


No comments:

Post a Comment