Related questions
Please written by computer source
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 #endifmain.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.
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 2 images
- Create a C++ linked list class for integers. Appending, inserting, and removing nodes should be class member functions. Add a list destructor. Drive the class. Add a print function to your linked list class. Display all linked list values. Start with an empty list, add elements, and print the list to test the class.arrow_forwardWhat would be a way in implementing the Josephus problem in C++ using a vector or a list? That takes in three parameters, one the number of knights for the knight parameter. The second parameter, "skip", is the number of knights to skip and to execute the next night. Then the third parameter "start", is the index of the knight to execute first.arrow_forwardCan you please help me with this code because i am struggling on how to do this, this code has to be in C code.question that i need help with:Priority with round-robin schedules tasks in order of priority and uses round-robin scheduling for tasks with equal priority. There will be multiple queues in the system each representing one priority class. For ease of implementation, you need total 1 through max_priority numbers of queues. You should start scheduling job out of the max priority queue and serve the members of the queue following RR. The schedule of tasks has the form [task name] [priority] [CPU burst], with the following example format: T1, 4, 20 T2, 2, 25 T3, 3, 25 T4, 3, 15 T5, 10, 10 The output should look like this: Running task = [P1] [4] [5] for 5 units. Task P1 finished. Running task = [P5] [3] [4] for 4 units. Task P5 finished. Running task = [P4] [2] [7] for 1 units. Task P4 exhausted its Quantum hence will be Rescheduled. Running task = [P3] [2] [1] for 1 units. Task...arrow_forward
- An actual working program in C that transfers contents of a file into a linked list and then performs insertion, updation, deletion and search operation on the contents of the file through a linked list. The contents of the file should be treated as a string. And all operations performed on the linked list should reflect on the file. The format of the file is: 112.22.33.44 Baker 101.32.11.23 Parson and so on.. and each line in the file should be treated as a string.arrow_forwardQuestion: May I ask for your help in giving me an idea for a C function that can sort my nodes based on their priority number through the linked list? I have my code attached below, but not the text file needed for this. I can provide a screenshot of it. Code: #include <stdio.h> #include <stdlib.h> #include <string.h> // Struct to hold each member related to my variable. typedef struct { char variable[10]; int Burst_time; int Wait_time; int Turn_time; int priority; } element_t; // Struct that acts as my node in a linked list. typedef struct priority_node { element_t data; struct priority_node *next; } node_t; // Assigning the functions here that will be used throughout main. node_t *insert_node (int priority); void display_list (); // Here is my main function. int main(void) { int i = 0; char line[25]; // Place that stores all of my text. char *variable, *priority, *Burst_time, *Wait_time; int elem, sum1 = 0, sum2 = 0, priority2; element_t elem_struct; node_t...arrow_forwardPlease do this in C++. The only parts needed are commented as //TODO in MAIN. Please do not use cout, the PrintNodeData in MileageTrackerNode.cpp needs to be called. I am struggling with adding data into the linked list. Given the MileageTrackerNode class, complete main() to insert nodes into a linked list (using the InsertAfter() function). The first user-input value is the number of nodes in the linked list. Use the PrintNodeData() function to print the entire linked list. DO NOT print the dummy head node. Ex. If the input is: 3 2.2 7/2/18 3.2 7/7/18 4.5 7/16/18 the output is: 2.2, 7/2/18 3.2, 7/7/18 4.5, 7/16/18 Main.cpp #include "MileageTrackerNode.h"#include <string>#include <iostream>using namespace std; int main (int argc, char* argv[]) {// References for MileageTrackerNode objectsMileageTrackerNode* headNode;MileageTrackerNode* currNode;MileageTrackerNode* lastNode; double miles;string date;int i; // Front of nodes listheadNode = new...arrow_forward
- Write a program in c++ to remove duplication if exists in the linked list. Write 2 separate functions to perform search and other to perform the duplication removal. Note: the above mentioned task is to be performed using singly linked list and in c++arrow_forwardProvide full C++ code Building a playlist (of songs) using a linked list and making some operations such as adding songs, removing songs, shuffling them, etc. (Some parts of this lab will closely follow lab 08 - it is imperative that you complete that lab before working on this project). A Node representing a song has the following data members (similar to struct Node of lab 08, except it doesn't have one member for storing data): string uniqueID string songName string artistName int songLength Node* nextNodePtr Your code must have the following three files: Playlist.h - Class declaration for a linked list of Nodes (very similar to lab 08 but with some changes to methods, as described below) with following private data members: private:Node* first;Node* last;int size; Playlist.cpp - Class definition main.cpp - main() function Checkpoint A For checkpoint A, you need to build a playlist (of songs) by readings data members of several songs from a file and printing them. Implement...arrow_forwardWrite a merge function that takes pointers to two sorted lists as arguments and returns a pointer to a merged list in C++. Please explain with detailed. Thank you!arrow_forward
- Write a C++ code that compare the times to traverse a list (containing a large number of elements) implemented in an array, in a simple linked list, and in an unrolled linked list.arrow_forwardWrite C++ code to display all even numbers in the a doubly linked list pointed to by Dlist. Use while loop to scan all nodes from the start to the end. (Each node has three fields: a data field that contains the information, and right and left fields contain pointers to nodes on either side. Ex. p->left represents the address of the node to the left of node p) (any number of nodes in the linked list) Dlist 4 3 8 HIIN 7 1arrow_forward
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education