January 8th, 2013, 11:05 AM
I neeed help plz about linked list.
hello to everyonee first iu want to thank all the persons who are here for helping and teaching us . you are doing great job .
i neeed i help to creat this functions in c programming because i am not good in this langauge i am doing my best to lurn this language and be better than i am now. thanks . :)
Create a file where you have all the necessary information about persons.
A person is known by his name, surname, sex, date of birth (day, month, year), an ID (5 character eg P0001), the number of children.
All persons will be stored in a linked list.
Functions to do:
- Load the data file into a list of persons (using a structure person).
- Add a person in the list.
- Add the children of a person.
- Remove a person from the list.
- Consult the list of persons.
- Search for a person by name or surname.
- View the number of children of the person given in parameter.
- Return the age of a person.
- Modify the records of a person (update).
- Sort the list according to the person's name and ID.
- Save list data in file.
- Add useful functions if necessary.
Creating a menu for functions.
January 8th, 2013, 03:08 PM
Use divide and conquer. Take the large task and break it up into its component small tasks, each of which do basically one thing and hence is easy to do. Ideally, each small task will be performed by one function.
Start by defining the structure of the node, what its fields are and what its pointer fields will point to. I would assume that this is a simple single-linked list, so you'd have a single pointer field pointing to the next node.
Work out how to create a new person node. Then work out how to add/insert this new node into the list. Is it an ordered list (ie, are the nodes sorted in some kind of order?)? What field are you sorting on? -- I would assume the ID field.
Work out how to delete a node.
Both inserting and deleting imply that you be able to search the list for a particular node. Finding a particular person's node to modify/update it also requires that you be able to find it. A preliminary step in figuring out how to find a particular node would be the ability to traverse the list node-by-node, so an early simple task to implement would be to traverse the list and print out information about that person in the order you encounter them; this will also be useful as a way to verify that you're inserting them in the right order and that you're removing the right one, etc.
When working with linked lists, it's often useful to sketch diagrams of the operations you're trying to perform so that you can work out the steps and details of the task before you start coding it.
After you have implemented the basic functions, then the solution to the other tasks on your list will be more apparent.
January 8th, 2013, 05:02 PM
thanks for the ideaaa ..but i would better know to save it in a file and load it form it ??
January 8th, 2013, 08:42 PM
That's called serialization. It won't do you any good to write pointers to a file, of course. A simple solution would be to write the node data files out to the file in the order that those nodes occur in the list, then when you read the file back in, you simply re-create the list with the nodes in the order that you read them in.