Página de Guillaume Hoffmann

View on GitHub

% Structures, pointers and linked lists

Due date: tuesday 27/6.

1. Pointers

  1. Answer the exercises 1 to 15 of Chapter 2.

  2. Start from the program given at https://goo.gl/9VuMdX

    Write a function map that takes as arguments:

    • an array of int
    • the size of the array given in int
    • a pointer to a function that takes an int and returns an int The function does not return any value.

    When given an array aand a function f, map replaces each element a[i] of array a by f(a[i]).

    Write two functions int plusOne(int) and int square(int).

    Add to the main fuction the required code to apply funcions plusOne and square to the array by using the map function.

    (There is no need to add printf statements since PythonTutor enables us to directly visualize the array).

2. Linked Lists

  1. Reimplement Program P3.1 in PythonTutor, doing the following changes:

    • as PythonTutor does not support program inputs, use the standard pseudorandom numbers generator instead of scanf to get random values between 0 and 9.
    • build a linked list of 4 elements
    • do not printf anything
    • Can you use only two pointers in the main function?
    • Add a function freeLL that frees the memory occupied by the linked list; use it.