Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is C++ programming Linked lists are dynamic data structures that allow storing a list of items in separate places in the memory. Each item

This is C++ programming

Linked lists are dynamic data structures that allow storing a list of items in separate places in the memory. Each item of the list, together with the address of the next item,is placed in one object of type Node (find the description below). The last node of the list should include the last item and a null pointer (NULL or nullptr). Lists, as abstract data types, can be implemented by different structures, including arrays and linked lists. Please do not use arrays for this practical. In this practical, you should write the code for two classes named LinkedList, and Node. You must include separate header and implementation files for both classes. The class Node should consist of two member variables, an integer data and a pointer to Node next, and 5 functions, a constructor, and getter and setter for the two member variables. The class LinkedList should have only one member variable: header, which is of type pointer to Node. If the list is empty, header should contain NULL or nullptr . It should also have at least the following member functions. Dont forget to write test cases for each function and ensure that the tests pass before progressing to the next function.

void addFront(int newItem): The function inserts a new node, containing the newItem, at the beginning of the list.

void addEnd(int newItem): The function inserts a new node, containing the newItem, at the end of the list.

void addAtPosition(int position, int newItem): The function inserts a new node, containing the newItem, such that it is the position-th member of the list.i.e. we assume the first element of the list is in position 1. If position is larger than the size of the list, the new item is added to the end of the list. If position<1, thenew item is added at the beginning of the list.

int search(int item): The function searched the list for the item, and if found,both prints the position of the of the item (followed by a space) and returns the position of the item in the list (positions start from 1). If not found, both prints 0 (followed by a space) and returns 0.

void deleteFront(): The function deletes the first element of the list.

void deleteEnd(): The function deletes the last element of the list.

void deletePosition(int position): The function deletes the element at the given position of the list. If the position1 or it is larger than the size of the list, only print outside range.

int getItem(int position): The function both prints the value of the item (followed by a space) and returns the value of the item at the given position of the list,If beyond the size of the array, both prints std::numeric limits < int >::max()(followed by a space) and returns std::numeric limits < int >::max(). You should include for this.

void printItems(): The function prints the value of the items of the list from head to tail. In case of an empty list, it does not print anything

A constructor with no parameters, which makes an empty list.

A constructor that takes an array of integers and makes a linked list, containing all the elements of the array, in the same order. As the second parameter, it takes the size of the array.Note that the printing in the functions search and getItem is for the purpose of easy testing.

2.4 Main function

You are asked to create a main function (main.cpp). It takes in one line of input.int1 int2 ... intn FUNCTIONINITIAL param1 param2 int1, until intn are integers, separated by space, which should be placed in an integer array, and passed to the linked list constructor. For simplicity, we assume that the size of this array never exceeds 100; therefore, you can take an static array with the size of 100.After the elements of the list, the input consists of an string, denoting a function, followed by its parameters. The string is one of these:

AF standing for addFront

AE standing for addend

AP standing for addAtPosition

S standing for search

DF standing for deleteFront

DE standing for deleteEnd

DP standing for deletePosition

GI standing for getItem Call the indicated function with its parameter. If the function has only one parameter, then the last integer value from the input is not used. At the end, call the function printItems, to produce the required output.

Sample input: 5 2 7 10 AP 3 9

expected output: 5 2 9 7 10

Sample input: 3 4 2 1 DP 3 0

expected output: 3 4 1

Sample input: 45 20 2 10 GI 3 0

expected output: 2 45 20 2 10

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

DB2 Universal Database V7.1 Application Development Certification Guide

Authors: Steve Sanyal, David Martineau, Kevin Gashyna, Michael Kyprianou

1st Edition

0130913677, 978-0130913678

More Books

Students also viewed these Databases questions

Question

=+ a. A change in consumer preferences increases the saving rate.

Answered: 1 week ago