Download presentation
Presentation is loading. Please wait.
Published byประมนต์ พันธุเมธา Modified over 5 years ago
1
Assignment 5 … Data Next pointer Data Next pointer Data Next pointer
Class material may be found on optlab.mcmaster.ca in ./COMPENG701_5_C/C_lecture.zip, login/pwd: ces701 0. Install LCC on your machine. The validity of your code will be tested against this compiler. Install Cygwin and gcc as described in class (refer to Kevin Sheppard’s webpage for configuration needed). Write a C program to manipulate a one-directional closed linked list. An entry of the list will contain the name of a person (string), a year of birth (integer) and weight (double). Your program must have a command-line interface, e.g., “Press H for help, 1 – to add a new entry, 2 – to delete current entry, …” and support the following functionality: add a new entry to the list (ask for name, date of birth, weight), print current entry in the list onto the screen (display the information above for the current entry), find a first entry in the list that matches search criteria which may be specified as name, weight or date of birth, delete current entry from the list, delete all the entries in the list, quit. Your program must create new entries in the dynamic memory using, say, calloc/free functions. No static pre-allocation of the list entries is allowed (you cannot simply reserve a large array upfront to store all your data). Hints: For your code, you might want to: define a structure type having fields Name, DOB, Weight and Next using typedef, where Next is the pointer to the next entry in the list, define an auxiliary pointer to the current entry in the list and set it to NULL if the list is empty, navigate through the list using something like CurrentEntry=(*CurrentEntry).Next, make sure you clean up the memory once the entry is deleted from the list. The following diagram explains what a closed single linked list is: Data Next pointer Data Next pointer Data Next pointer … Data Next pointer
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.