To gain an understanding of dynamic memory allocation and linked lists.
- Write a program
linkedlist.c
creating a node structure as described in class. Implement the following functions for integers:printList()
: given a linked list, print out the listadd()
: given a linked list and an integer, add a node with the integer to the beginning of the list.remove()
: given a linked list and an integer, remove the first instance of that integer in the list. Print an error message if the integer is not found.clear()
: given a linked list, empty the entire linked list (delete all nodes).smallestLength()
: Given two linked lists of integers, write a function to find the length of the smallest list.smallestSum()
:Given two linked lists of integers, write a function to find the list with the smallest sum
In a text file assignment9.txt
, answer the following questions:
- Thoroughly compare and contrast malloc() and calloc(). Make sure to include details about parameters, return values, etc.
- How would you determine the size of an allocated portion of memory?
- Why do you have to free memory on the heap but not on the stack?
- Why do you need to test the return value from malloc?
Please include your name and a description in a comment at the top of your code files. Please also include your name at the top of your assignment9.txt
file.
All files must be submitted via GitHub by 10:10am 8/5.