Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in C++ create linked list class class LinkedList Data Members protected ListElement *head; A pointer points the beginning of a singly linked list that stores

in C++ create linked list class

class LinkedList

Data Members

protected ListElement *head;

A pointer points the beginning of a singly linked list that stores ListElement type nodes. ListElement class is an inner class of the LinkedList class and the class implementation is already provided in the LinkedList header file.

protected ListElement *cursor;

A pointer points a list node where the next list operations will be applied.

Member Functions

Constructor

Copy Constructor

LinkedList(const LinkedList &src);

Destructor

Deallocates the memory used to store a list.

void insert(const Type &item, int i);

When a list is not full, inserts the item into a list.

If the list is empty, inserts the item as the first element in the list. The head and cursor pointer should be initialized properly after the insert operation. If the list is not empty and the second integer argument has the value of 0, inserts the item immediately after the cursor element. If the list is not empty and the second integer argument has the value of -1, inserts the item immediately before the cursor element.

In all case, properly move the cursor to designate inserted item as the current element.

void remove();

When a list is not empty, removes the current element from the list. After deleting the cursor pointing element, set the cursor to the following element. If the cursor is pointing to an element that is the only element in the list, you should properly set the head and cursor pointer after deleting the node. If the cursor is pointing to the last element of the list, the link field of the previous node of the last node should be set to

null after deleting the node. Set the cursor to the head pointing element.

Type retrieve() const;

When a list is not empty, return a copy of the cursor pointing element.

int gotoPrior();

If a list is not empty and the cursor is not pointing the first element of the list, then designates the element immediately before the current element as the current element and returns 1. Otherwise, returns 0.

int gotoNext();

If the current element is not at the end of the list, then designates the element immediately after the current element as the current element and returns 1. Otherwise, returns 0.

int gotoBeginning();

If a list is not empty, then designates the element at the beginning of the list as the current element and returns 1.

Otherwise, returns 0.

void clear();

Removes all the elements in a list and deallocates associated dynamic memory.

int empty() const;

Returns 1 if a list is empty. Otherwise, returns 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

Distributed Relational Database Architecture Connectivity Guide

Authors: Teresa Hopper

4th Edition

0133983064, 978-0133983067

More Books

Students also viewed these Databases questions

Question

Explain the process of Human Resource Planning.

Answered: 1 week ago