Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Code in c The purpose of this lab is to get your first exposure to implementing a linked list. Begin by implementing the following function:
Code in c
The purpose of this lab is to get your first exposure to implementing a linked list. Begin by implementing the following function: List initIntegerList ) All this will do is return whatever you define to be an empty list, e.g. NULL, and will be called as List head; head initIntegerListO Next implement a function, insertInteger, that inserts a given integer at the head of a list. You'll need to determine the prototype you think is best. What will happen if there's insufficient memory to complete the insertion? How will the user know this has occurred? The next function, printList (List ,can be called by the user to print the integers in a given list. You'll find this function useful for verifying that your insertion function is working properly. And the final function, freeList, should free all memory allocated for a given list. Be sure to never access the content of any memory after it's been freed! You may want to consider implementing it so that the user's pointer is set to NULL in the process, i.e., to prevent the user from accidently referencing freed memory afterward Once you're done with all of this, you may want to try re-implementing the functions to make use of a dummy node like I discussed in lecture (doing so is entirely optional and is neither required nor expected). Now initIntegerList will return a pointer to a list node instead of NULL, so you can implement insertInteger with a prototype like: int insertInteger (int k, 1ist) where the return value signifies whether the integer was successfully inserted. Note that you don't need to pass the list by reference because the value of1ist will never change. This will become clear when you implement it - JKU
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started