Skip to content

jaredwassermanCPRF/Assignment9

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Assignment 9

Objectives

To gain an understanding of dynamic memory allocation and linked lists.

Part 1

  1. 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 list
    • add(): 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

Part 2

In a text file assignment9.txt, answer the following questions:

  1. Thoroughly compare and contrast malloc() and calloc(). Make sure to include details about parameters, return values, etc.
  2. How would you determine the size of an allocated portion of memory?
  3. Why do you have to free memory on the heap but not on the stack?
  4. Why do you need to test the return value from malloc?

Submission Guidelines

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.

Releases

No releases published

Packages

No packages published

Languages

  • C 100.0%