List exercises
Comments and questions to John Rowe.
The following use our particle structure defined in the lecture.
To speed things up,
do not type the data in at the keyboard, either modify the
code to read from a file or use copy and paste (for example by
putting the input data in a comment after the code).
- Write a function to find the mass of the whole list of particles.
- Write a function that takes two arguments, the start of the list
and a particle of interest, and returns the value of the
furthest distance of another particle to it.
- Write a function to find the distance between the
two furthest-separated particles in the system. Tip: this
should call the previous function.
- Free each element of the list.
- [Advanced] Add to the structure so each particle has a name.
Comment out the previous "free" task and
write
a function to delete any particle with a given name. (Remember
strcmp().) As a very
advanced feature do not
assume all the names are different.
Log in