Data structure - Online Exam Test Papers | Data structure - MCQs[multiple choice questions and answers ] | Data structure - Mock Test Papers | Data structure - Practice Papers | Data structure - Sample Test Papers |

Question:
How do you count the number of elements in the circular linked list?

1.public int length(node head){int length = 0;if( head == null)return 0;node temp = head.getnext();while(temp != head){temp = temp.getnext();length++;}return length;}

2. public int length(node head){int length = 0;if( head == null)return 0;node temp = head.getnext();while(temp != null){temp = temp.getnext();length++;}return length;}

3. public int length(node head){int length = 0;if( head == null)return 0;node temp = head.getnext();while(temp != head && temp != null){temp = head.getnext();length++;}return length;}

4.public int length(node head){int length = 0;if( head == null)return 0;node temp = head.getnext();while(temp != head && temp == null){temp = head.getnext();length++;}return length;}

Posted Date:-2022-07-05 11:31:14


More MCQS Questions and answers

Search