Due: Tuesday 10/19 8:00 am
GitHub Submission Link: git@github.com:mks65/10_list.git
New Additions for Monday
- Your list functions should be in a .c/.h library, with a separate .c file used for testing.
- This should all be compileable via
$ make
and runable via$ make run
struct node * remove_node(struct node *front, int data)
- Remove the first node containing
data
from the list pointed to byfront
. - If
data
is not in the list, nothing is changed. - Returns a pointer to the beginning of the list.
- Remove the first node containing
- Don’t forget to test out these various functions to ensure they work correctly. (Just to be clear, when you run the program and get “Segmentation fault” that means it’s not working.). Here is a sample run that shows things being tested (better output coming later):
Task at hand
- Write a simple linked list program.
- You should start with your struct from the previous assignment, but add to it:
- A pointer to a struct of the same type (the next node).
-
Here’s an example of what the struct could look like:
struct user_node { int id; char name[200]; struct user_node *next; };
- Create the following functions:
void print_list(struct node *)
- Should take a pointer to a node struct and print out all of the data in the list
struct node * insert_front(struct node *, int)
- Should take a pointer to the existing list and the data to be added, create a new node and put it at the beginning of the list.
- The second argument should match whatever data you contain in your nodes.
- Returns a pointer to the beginning of the list.
struct node * free_list(struct node *)
- Should take a pointer to a list as a parameter and then go through the entire list freeing each node and return a pointer to the beginning of the list (which should be NULL by then).