Work 2: enlist your coding skills

posted Oct 7, 2016, 7:12 AM by JonAlf Dyrland-Weaver
Write a simple linked list program. You will need a define a node struct with the following data members:
  • A piece of data (your choice, but make it a primitive data type)
  • A pointer to the next node
  • Put the struct declaration at the top of your code (after the include lines), or in a separate .h file
  • Here's an example of what the struct could look like:
      • struct node { int i; struct node *next };
Create the following functions:
  • print_list
    • Should take a pointer to a node struct and print out all of the data in the list
  • insert_front
    • Should take a pointer to the existing list and the data to be added, create a new node, put it at the beginning of the list and return a pointer to the beginning of the list.
  • free_list
    • 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).                
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.)

Github link:
https://github.com/mks65/list.git
Comments