Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This assignment is an exercise in building a linked list in C. Part 1 We want to build a linked list of int values in
This assignment is an exercise in building a linked list in C. Part 1 We want to build a linked list of int values in C. Let's start with the following structure definition: struct node int value; struct node* next; This is the data structure we will use for our linked list nodes. Because C does not have objects, or encapsulation, we will write functions to operate on these nodes directly. In other words, we will think of lists and nodes interchangeably in this assignment Write a C function with the following prototype (this is another word for a function declaration, and specifies a function's return type, as well as the number and types of parameters) struct node* new node(int value, struct node* next) This function should malloc enough room for a struct node, and initialize the struct's fields to the correspond- ing parameters. Return that freshly malloc'd node. Question 1: What does new_node do, in terms of list operations? Note: The header file stdlib.h declares malloc and free. It also defines the NULL macro, which expands to ((void )0) Question 2: How do we interpret this syntax: ((void )0)? Note: because you will be dealing with a struct using a pointer, the arrow operator is the best way to access the struct fields. For example, if we have a variable struct node* n pointing to some list node, you can access
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started