1.

A linked list is formed from the objects of the class Node. The class structure of the Node is given below: class Node { int num; Node next; } Write an Algorithm OR a Method to count the nodes that contain only odd integers from an existing linked list and returns the count. The method declaration is as follows : int CountOdd (Node startPtr)

Answer»

 int countOddNodes(Node myNode){ 

int count = 0 

while(myNode.next != null) { 

if(myNode.num%2 = = 0) { 

count ++; 

myNode= myNode.next; 

return count; 

}



Discussion

No Comment Found

Related InterviewSolutions