Question: Type in C++ programming!!! Topics: Recursive Structs, Pointers and Memory Management in C. For this assignment, you will add to your multi-file C program (Program

Type in C++ programming!!!

Type in C++ programming!!! Topics: Recursive Structs, Pointers and Memory Management in

C. For this assignment, you will add to your multi-file C program

Topics: Recursive Structs, Pointers and Memory Management in C.

For this assignment, you will add to your multi-file C program (Program 04) to define, implement and use a third kind of dynamic linked list. Please refer to Lab 04 for the definition of a basic dynamic linked list.

In this assignment you will need to use the basic ideas of a node and of a linked list (of nodes) to implement two more functions which can be used to create and maintain a new kind of list.

Inorder:

  1. A list where adds and removes occur such that the list is always in (ascending) sorted order

Requirements:

  • You must add to your lists.c - given the following lists.h (which can not be modified):

// a recursive data type definition

// serves as the nodes of a list

typedef struct node

{

int id;

char* name;

struct node* next;

} node;

// create an empty list - set *node = NULL

void create_list(node** head);

// add a new node to the front of the list

void add_front(node* *head, node* new_node);

// add a new node to the end of the list

void add_end(node* *head, node* new_node);

// add a new node in the list, in (ascending) sorted order based on

// the nodes name component's value

void add_inorder(node* *head, node* new_node);

// remove and return the first node in the list whose name component's value

// is equal to the given key_name

// return NULL if no such node exists in the list

node* rem_inorder(node* *head, char* key_name);

// remove and return the node at the front of the list or NULL if empty

node* rem_front(node* *head);

// remove and return the node at the end of the list or NULL if empty

node* rem_end(node* *head);

// return the number of nodes in the list

int list_len(const node* head);

// print the data values of all the nodes in the list (from start to end)

void print_list(const node* head);

// free the entire list and set *node = NULL

void free_list(node* *head);

  • You must add to your main.c so that it tests your Inorder list implementation completely
  • You should not need to modify your Makefile

/***********Program04****/

typedef struct node { int id; char* name; struct node* next; } node;

// add a new node to the front of the list

void add_front(node* *head, node* new_node) { if(*head==NULL) { *head=new_node; return; } new_node->next=*head; *head=new_node; }

// add a new node to the end of the list

void add_end(node* *head, node* new_node) { if(*head==NULL) { *head=new_node; return; } node * ptr= *head; while(ptr->next!=NULL) { ptr=ptr->next; } ptr->next=new_node;

}

// remove and return the node at the front of the list or NULL if empty

node* rem_front(node* *head) { if(*head==NULL) return NULL; node * ptr= *head; *head= (*head)->next; return ptr; } // remove and return the node at the end of the list or NULL if empty

node* rem_end(node* *head) { if(*head==NULL) return NULL; node * ptr= *head; while(ptr->next->next!=NULL) { ptr=ptr->next; } node *temp=ptr->next; ptr->next=NULL; return temp; } // return the number of nodes in the list int list_len(node* head) { if(head==NULL) return 0; node * ptr = head; int len=0; while(ptr!=NULL) { len++; ptr=ptr->next; } return len; }

// print the data values of all the nodes in the list (from start to end) void print_list(node* head) { if(head==NULL) return; node * ptr = head; while(ptr!=NULL) { coutid"; ptr=ptr->next; } coutnext; delete(temp); } *head=NULL; }

int main() { /ew list node * head=NULL; //add at front node * temp = (node *) malloc(sizeof(node)); temp->id= 1; add_front(&head,temp); //add at front temp = (node *) malloc(sizeof(node)); temp->id= 2; add_front(&head,temp); //print coutid= 3; add_end(&head,temp); //add at end temp = (node *) malloc(sizeof(node)); temp->id= 4; add_end(&head,temp); //print cout Topics: Recursive Structs, Pointers and Memory Management in C. For this assignment, you will add to your multi-file C program (Program 04) to define, implement and use a third kind of dynamic linked list. Please refer to Lab 04 for the definition of a basic dynamic linked list. In this assignment you will need to use the basic ideas of a node and of a linked list (of nodes) to implement two more functions which can be used to create and maintain a new kind of list. Inorder: 1. A list where adds and removes occur such that the list is always in (ascending) sorted order Requirements: . You must add to your lists.c- given the following lists.h (which can not be modified): // a recursive data type definition // serves as the nodes of a list typedef struct node int id; char* name; struct node* next; } node; // create an empty list - set *node = NULL void create_list (node** head); // add a new node to the front of the list void add_front (node* *head, node* new_node); // add a new node to the end of the list void add_end (node* *head, node* new_node): || // add a new node in the list, in (ascending) sorted order based on // the nodes name component's value void add_inorder (node* *head, node* new_node); 11 remove and return the first node in the list whose name component's value // is equal to the given key_name // return NULL if no such node exists in the list node* rem_inorder (node* *head, chart key_name); // remove and return the node at the front of the list or NULL if empty node* rem_front (node* *head); // remove and return the node at the end of the list or NULL if empty node* rem_end (node* *head); // return the number of nodes in the list int list_len (const node* head); // print the data values of all the nodes in the list (from start to end) void print_list (const node* head); // free the entire list and set *node = NULL void free_list (node* *head); You must add to your main.c so that it tests your Inorder list implementation completely You should not need to modify your Makefile . Topics: Recursive Structs, Pointers and Memory Management in C. For this assignment, you will add to your multi-file C program (Program 04) to define, implement and use a third kind of dynamic linked list. Please refer to Lab 04 for the definition of a basic dynamic linked list. In this assignment you will need to use the basic ideas of a node and of a linked list (of nodes) to implement two more functions which can be used to create and maintain a new kind of list. Inorder: 1. A list where adds and removes occur such that the list is always in (ascending) sorted order Requirements: . You must add to your lists.c- given the following lists.h (which can not be modified): // a recursive data type definition // serves as the nodes of a list typedef struct node int id; char* name; struct node* next; } node; // create an empty list - set *node = NULL void create_list (node** head); // add a new node to the front of the list void add_front (node* *head, node* new_node); // add a new node to the end of the list void add_end (node* *head, node* new_node): || // add a new node in the list, in (ascending) sorted order based on // the nodes name component's value void add_inorder (node* *head, node* new_node); 11 remove and return the first node in the list whose name component's value // is equal to the given key_name // return NULL if no such node exists in the list node* rem_inorder (node* *head, chart key_name); // remove and return the node at the front of the list or NULL if empty node* rem_front (node* *head); // remove and return the node at the end of the list or NULL if empty node* rem_end (node* *head); // return the number of nodes in the list int list_len (const node* head); // print the data values of all the nodes in the list (from start to end) void print_list (const node* head); // free the entire list and set *node = NULL void free_list (node* *head); You must add to your main.c so that it tests your Inorder list implementation completely You should not need to modify your Makefile

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!