Home CPSC 340

Recursion Exercise

Objective

To gain experience writing recursive functions.

Task

Some data structures naturally lend themselves to recursion. One of these is liked lists. When we define the node of a linked list, we are already using a form of recursion:


struct Node {
  type data;
  Node* next;
};

Here a Node is defined as having data, and a pointer to another Node. Because Nodes are mentioned in the definition of a Node, this is recursive.

We can use the fact that Nodes are defined recursively to write recursive functions for dealing with linked lists. For this lab, you will write a function to print a singly-linked list using recursion instead of iteration. You will also write a function to print a singly-linked list backwards using recursion. This is more difficult without recursion, but extremely simple with it.


Details


Submitting

When you're done, email the code to ifinlay@umw.edu.

Copyright © 2018 Ian Finlayson | Licensed under a Creative Commons Attribution 4.0 International License.