With your table look at exercise1.rb
and answer the following questions.
- Before you run the program, what do you think it does?
- Draw the resulting Linked List.
- What do you think it prints out, run the application and verify your answer.
- Before you run the program, what do you think is happening with Block 1?
- What do you think happens in Block 2?
- Draw the resulting Linked List.
- What do you think it prints out, run the application and verify your answer.
- What would happen if you deleted the line
current = current.next_node
from line 25?
- Block 1 loops through and creates a list of nodes from 1-8. What does block 2 do?
- What will
back
be referring to at the end? Run the program and verify your prediction.
The code segment in exercise 4 creates a new list. Try to implement a find method to find if a value is in the list or not.
Write a method which reverses the original list, it will return a reference to a node which is the head of the reversed list.