next up previous
Next: Printing the elements of Up: Unit 12 Previous: Printing the elements of

Lists as inductive structures

A different way to perform an operation on all elements of a list is by exploiting the fact that lists are inductive structures:

Exploiting the inductive characterization of lists, we can realize all operations on list also through recursion. The typical structure of a recursive method that operates on a list is as follows:

if (the list is empty) {
  perform the operation for the empty list
} else {
  perform the operation on the first element of the list
  call the method recursively on the rest of the list
}


next up previous
Next: Printing the elements of Up: Unit 12 Previous: Printing the elements of