Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C only please !!! The purpose of this lab is to get your first exposure to implementing a linked list. Begin by implementing the

In C only please!!!

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 = initIntegerList();

Next implement a function, insertInteger, that inserts a given integer at the head of a list. Youll need to determine the prototype you think is best. What will happen if theres 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. Youll 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 its been freed! You may want to consider implementing it so that the users pointer is set to NULL in the process, i.e., to prevent the user from accidentally referencing freed memory afterward.

Once youre 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, *list)

where the return value signifies whether the integer was successfully inserted. Note that you dont need to pass the list by reference because the value of the list will never change. This will become clear when you implement it.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced Database Systems

Authors: Carlo Zaniolo, Stefano Ceri, Christos Faloutsos, Richard T. Snodgrass, V.S. Subrahmanian, Roberto Zicari

1st Edition

155860443X, 978-1558604438

More Books

Students also viewed these Databases questions