Question: Assignment 3 : Recursion and Linked Lists in C The purpose of this assignment is to work with recursion and linked lists in the C
Assignment : Recursion and Linked Lists in C
The purpose of this assignment is to work with recursion and linked lists in the C programming language. You will be required to implement various functions using iteration as well as recursion to manipulate linked lists.
Instructions:
Implement the following functions:
a int listLength Node head: This function should take the head pointer of a linked list as input and return the length Leing iteration.
bint listLengthrecursive Node head: This function should take the head pointer of a linked list as input and return the length recursively.
c int listSum Node head: This function should take the head pointer of a linked list containing integer values and return the sum of all elements in the list using iteration.
d int listSum
recursiveNode head: This function should take the head pointer of a
linked list containing integer values and return the sum of all elements in the list recursively.
e void printList Node head: This function should take the head pointer of a linked list and print the elements using iteration.
f void printList recursive Node head: This function should take the head pointer of a linked list and print the elements using recursion.
g void printListReverse Node head: This function should take the head pointer of a linked list and print the elements in reverse order using iteration.
h void printListReverserecursive Node head: This function should take the head pointer of a linked list and print the elements in reverse order using recursion.
Define the structure Node for a singlylinkedlist:typedef struct Node
int data;
struct Node next;
Node;
Implement a function Node createNode int data that creates a new node with the given data and returns its pointer.
Implement a function Node insertNode Node head, int data that inserts a new node with the given data at the beginning of the linked list and returns the updated head pointer.
Write a main function to test your implemented functions. Create a linked list by inserting nodes using the insertNode function and perform the following operations:
a Insert at least five nodes with integer values of your choice.
b Print the linked list using printList and printListrecursive
c Call the listLength and listLengthrecursive functions and display the lengthofthelistd Call the listSum and listSumrecursive functions and display the sum of all elements in the list.
e Call the printListReverse and printListReverserecursive functions and print the elements of the linked list in reverse order.
Perform a Big O analysis of all the functions, except the main function. Explain clearly and precisely how you calculated the Big O
Submission:
Write wellcommented and organized code. Clearly explain your algorithm, logic and purpose of each function in multiline comments above each function.
Include necessary header files and function prototypes.
Test your program with different scenarios and edge cases to ensure its correctness.
Proper memory management is required, if necessary.
Include a text file or a document explaining your approach and any challenges you encountered during the implementation.
Submit a zip folder containing a single C source file named assignment. c as well as a bigoanalysis.pdfdocument
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
