In this lab, you need to implement a simple linked list using dynamic memory allocation. The structure of node in the linked list has been declared in “lab3.h”. Also, the functions of linked list have been declared in “lab3.h” as well. In “main.c”, these functions are called. Your work is to finish these function implementations in a separate C source file, and create a makefile which can compile your separate C source file along with “main.c” and “lab3.h”. You can follow the comments in “main.c” and “lab3.h” to finish this lab. Please do not change “main.c” and “lab3.h”, because your separate C source file will be compiled with these two files posted on BlackBoard. When you test your program, please put “main.c”, “lab3.h”, your separate C source file and your makefile in the same directory and compile. Code provided: lab3.h #include #include #ifndef LAB3_H #define LAB3_H struct node { int data; struct node *next; }; struct node *init (); //initialize: create an empty head node (whose "data" is intentionally missing); This head node will not be used to store any data; void insert(struct node *head, int data); //Create a new node to store data and insert it to the end of current linked list; the head node will still be empty and data in the array in "main.c" are not stored in head node void display (struct node *head); //print data for all nodes in the linked list except the head node (which is empty) void deleteAll (struct node *head); //delete the entire linked list including the head node #endif main.c   #include"lab3.h" int main() { int array[]={1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; struct node *head; head = init(); //after this statement, a linked list has been created with only a head node int i; for (i=0;i<10;i++) { insert(head, array[i]); //create a new node to store an array element. This new node is inserted to the end of current linked list } display(head); //print data for all nodes in the linked list except the head node (which is empty) deleteAll(head); //delete the entire linked list including the head node return 1; } This is needed to be coded in C.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Please written by computer source

16

In this lab, you need to implement a simple linked list using dynamic memory allocation. The structure of node in the linked list has been declared in “lab3.h”. Also, the functions of linked list have been declared in “lab3.h” as well. In “main.c”, these functions are called. Your work is to finish these function implementations in a separate C source file, and create a makefile which can compile your separate C source file along with “main.c” and “lab3.h”.

You can follow the comments in “main.c” and “lab3.h” to finish this lab. Please do not change “main.c” and “lab3.h”, because your separate C source file will be compiled with these two files posted on BlackBoard. When you test your program, please put “main.c”, “lab3.h”, your separate C source file and your makefile in the same directory and compile.

Code provided:

lab3.h

#include<stdio.h> #include<stdlib.h> #ifndef LAB3_H #define LAB3_H struct node { int data; struct node *next; }; struct node *init (); //initialize: create an empty head node (whose "data" is intentionally missing); This head node will not be used to store any data; void insert(struct node *head, int data); //Create a new node to store data and insert it to the end of current linked list; the head node will still be empty and data in the array in "main.c" are not stored in head node void display (struct node *head); //print data for all nodes in the linked list except the head node (which is empty) void deleteAll (struct node *head); //delete the entire linked list including the head node #endif

main.c

 

#include"lab3.h" int main() { int array[]={1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; struct node *head; head = init(); //after this statement, a linked list has been created with only a head node int i; for (i=0;i<10;i++) { insert(head, array[i]); //create a new node to store an array element. This new node is inserted to the end of current linked list } display(head); //print data for all nodes in the linked list except the head node (which is empty) deleteAll(head); //delete the entire linked list including the head node return 1; }

This is needed to be coded in C.

 
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Linked List Representation
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education