Write a main program that creates a forward linked list of


Problem

Linked Lists

Objectives

• Get yourself familiar with the forward linked list creation and operations

• Manipulate pointers

• Do NOT use any STL containers

Overview

1. We wish to maintain several stocks in a linked list. Each stock has a stock symbol (STLstring), a cost (double, i.e. purchase price), the number of shares (int). One needs apointer to the next node in the linked list. There are at least the following three approaches

• Approach 1class stockNode {string symbol; double cost; int shares; stockNode *next; };

• Approach 2class stock {string symbol; double cost; int shares; };class stockNode {stock info; stockNode *next; };

• Approach 3class stock {string symbol; double cost; int shares; };class stockNode: public stock {stockNode *next; };

Choose approach 2 or 3.

2. Write a main program (lab4Main.cpp) that creates a forward linked list of at least 10elements, where each element holds a stock, without keeping track of list length. Noneed to have a separate stockDB class. This means the main program itself is equivalentto the stockDB class. In the main program for each stock, you can hard-code a stocksymbol (or just do S1, S2, etc.), cost, and shares (or you can randomly generate any ofthese three). Alternatively, you could choose to reading a stock file, which might beeasier.

3. From the main program, print the list.

4. Write the function "returnMiddleList" in the main program to find the middle elementof the linked list in one pass.

• This function splits the input list in half at the middle element to create twoentirely separate output linked lists of near equal size (+/- 1). In other words, write the "split in half" function.

• For each of the following cases, print the two output lists

a. The input list is an empty list.

b The input list has only one element.

c The input list has odd number of elements (> 1).

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: Write a main program that creates a forward linked list of
Reference No:- TGS02779350

Expected delivery within 24 Hours