Linked List Exercises

Exercise 1

With your table look at exercise1.rb and answer the following questions.

  1. Before you run the program, what do you think it does?
  2. Draw the resulting Linked List.
  3. What do you think it prints out, run the application and verify your answer.

Exercise 2

  1. Before you run the program, what do you think is happening with Block 1?
  2. What do you think happens in Block 2?
  3. Draw the resulting Linked List.
  4. What do you think it prints out, run the application and verify your answer.
  5. What would happen if you deleted the line current = current.next_node from line 25?

Exercise 3

  1. Block 1 loops through and creates a list of nodes from 1-8. What does block 2 do?
  2. What will back be referring to at the end? Run the program and verify your prediction.

Exercise 4

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.

Exercise 5

Write a method which reverses the original list, it will return a reference to a node which is the head of the reversed list.