Skip to content
Physics and Astronomy
Home Our Teaching Resources C programming Exercises
Back to top

List exercises

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).

  1. Write a function to find the mass of the whole list of particles.
  2. 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.
  3. Write a function to find the distance between the two furthest-separated particles in the system. Tip: this should call the previous function.
  4. Free each element of the list.
  5. [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
                                                                                                                                                                                                                                                                       

Validate   Link-check © Copyright & disclaimer Privacy & cookies Share
Back to top