Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

File supplied.o contains code that can build, display, and destroy a linear linked list . For this assignment, you will need to write the following

File supplied.o contains code that can build, display, and destroy a linear linked list.

For this assignment, you will need to write the following functions in list.cpp, add function prototypes for them to list.h, and call the functions in main.cpp. You should label the output of your test, such as list insertion complete, the list after insertion:, etc.

-int sumOfList(node * head) compute and return the sum of integers in the linear linked list.

-void insert(node *& head, int position, int newInt) insert newInt in a new node at index position where index starts with 0. In other words, the head node is position 0, head->next is position 1, etc. If the parameter position is less than or equal to zero, then place the new node at position 0. If position is greater than or equal to the length of the list, then place the new node at the end of the list. Notice that the head parameter is a reference to a pointer. So anything you do to head in insert() will modify the head pointer in main.

The code files will compile and run without modification, so you can see what build and display will do without adding any code. This may help you get started.

The function build() will create a linear linked list that is from 10 to 20 nodes in length.

-----------------------------------

The files are below.

--------------------------------------

//list.cpp

#include "list.h"

//put the implementation of your assigned functions here

//list.h

#ifndef LIST_H

#define LIST_H

#include

#include

#include

struct node

{

int data;

node * next;

};

/* These functions are already written and can be called to test out your code */

void build(node * & head); //supplied. The resulting list will have from 10 to 20 nodes.

void display(node * head); //supplied

void destroy(node * &head); //supplied

/* *****************YOUR TURN! ******************************** */

//Write your function prototype here:

#endif

//main.cpp

#include "list.h"

using namespace std;

int main()

{

node * head = NULL;

build(head); // build() and display() are provided by supplied.o.

display(head); // Don't try to write the function definitions for them.

//PLEASE PUT YOUR CODE HERE to call the functions assigned.

display(head);

destroy(head); // destroy() is also provided by supplied.o.

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 Processing

Authors: David Kroenke

11th Edition

0132302675, 9780132302678

More Books

Students also viewed these Databases questions

Question

KEY QUESTION Refer to columns 1 and 6 in the table for question

Answered: 1 week ago