Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN C! Starter code included! In the header file you are given, there is a struct called Node that has integer data variable and pointer

IN C! Starter code included!

In the header file you are given, there is a struct called Node that has integer data variable and pointer of type Node, which points to NULL for empty linked list. Below that there are several functions you have to implement in a separate c file.

** FUNCTIONS TO WRITE in SimpleLL.c **

void printList();

This function is used to print the value of the data for each node in a linked list. Using a while loop the code will traverse through the list printing each nodes integer data value as it goes through each node in the list. If the list is empty, print a message. Put a newline after printing each element.

void append(int num);

This function adds a node to the end of the linked lists. If the head is NULL then this means the list is empty. If it is it points the head to the newly created node. Create a temporary node with dynamic memory and initialize the data with numand set node equal to where head is pointing.

void addFront(int num);

This function will add a node to the front of the list. First it will allocate memory for the new node, returning the address of the allocated memory to a local variable. Next it will set the values of the data and next pointer for the new node.

void deleteList();

This function deletes the entire linked list

void removeNode(int num);

This function removes an element with value equal to num from the lists. If there are multiple occurrences of the same element, remove the first occurrence. If the value passed to the function is not found in the list, print a message and return.

int length();

This function calculates the size of the linked listNext we have given you driver.c that demonstrate that all functions that you implemented works. Program take input from user the integer you want to append, add to Back or remove and every time one of the functions called that changes the contents of the linked list, printList to print the entire list,

STARTER CODE in SimpleLL.h:

image text in transcribed

STARTER CODE in driver.c:

image text in transcribed

Blessings to those who help

10 1 #ifndef SIMPLELL_H 2 #define SIMPLELL_H 3 4 #include 5 #include 6 7 typedef struct Node 8 { 9 int data; struct Node *next; 11 }nodet; 12 13 node_t* head; 14 15 void printList(); 16 void append(int num); 17 void addFront(int num); 18 void deleteList(); 19 void removeNode(int num); 20 int length(); 21 22 23 24 #endif 25 #include "SimpleLL.h" 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 int main() { /*head is a global variable*/ head = NULL; int size =0; removeNode(1); append(2); append(3); addFront(1); append(4); printList(); size length(); printf("size now %d ", size); removeNode (8);| printList(); removeNode(1); printList(); removeNode (4); printList(); deleteList(); printList(); size = length(); printf("size after deletion %d ", size); return 0; }

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

Database Security XI Status And Prospects

Authors: T.Y. Lin, Shelly Qian

1st Edition

0412820900, 978-0412820908

More Books

Students also viewed these Databases questions

Question

How to use this book

Answered: 1 week ago

Question

6. Is all Internet training the same? Explain.

Answered: 1 week ago