% Structures, pointers and linked lists
Due date: tuesday 27/6.
1. Pointers
-
Answer the exercises 1 to 15 of Chapter 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 anint
The function does not return any value.
When given an array
a
and a functionf
,map
replaces each elementa[i]
of arraya
byf(a[i])
.Write two functions
int plusOne(int)
andint square(int)
.Add to the
main
fuction the required code to apply funcionsplusOne
andsquare
to the array by using themap
function.(There is no need to add
printf
statements since PythonTutor enables us to directly visualize the array). - an array of
2. Linked Lists
-
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.
- as PythonTutor does not support program inputs, use the standard
pseudorandom numbers generator instead of