The following code fragment is an implementation of the count-controlled traversal of a singly linked list from Section3.4.5. Does it work? If not, explain the problem and how to fix it. (Note: this.length is the number of data nodes in the linked list and assume the visit() method is implemented and works properly.)

```
SLNode cursor = head.getSuccessor();
for ( int count = 0; count <= this.length; count++ ) {
visit(cursor);
cursor = cursor.getSuccessor();
}


```


No, it does not work. The problem is with the condition of the for loop, count <= this.length. By doing this the loop will be performed 1 more than the end of the list because this.length gives the number of nodes starting from 1 but count starts from 0. Therefore there will be an error since cursor will be null. It can be corrected by making the condition count < this.length.

Computer Science & Information Technology

You might also like to view...

Write an HTML page that contains a text ¯eld for a credit card number and a button. When the button is clicked check that the text ¯eld has only numeric characters in it and check that the number of characters is 16. If not, use an alert dialog to inform the user.

What will be an ideal response?

Computer Science & Information Technology

Summary tasks are headings for grouped tasks

Indicate whether the statement is true or false

Computer Science & Information Technology

To change the font, locate the ____ group on the Home tab on the Ribbon.

A. Edit B. Proofing C. Save D. Font

Computer Science & Information Technology

A special type of search tool that compiles the search results from multiple search engines into a single search results list is a metasearch engine.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology