Question: I need help with some guides and reference to this TO-DO question(Code in C++): Some implementations of a singly linked list maintain the

I need help with some guides and reference to this "TO-DO" question(Code in C++):

Some implementations of a singly linked list maintain the size (number of elements in the list). std::forward_list does not. The size of singly linked list must be calculated on demand by walking the list from beginning to end counting the number of elements visited. The STL's std::distance() function does that, or you can write your own loop.

 I need help with some guides and reference to this "TO-DO"question(Code in C++): Some implementations of a singly linked list maintain the

MeditList.hpp

#pragma once // include guard

#include

#include // size_t

#include

#include

#include

#include // domain_error, length_error

#include

#include

#include

#include "MediaItem.hpp"

class MediaList

{

// Insertion and Extraction Operators

friend std::ostream & operator

friend std::istream & operator>>( std::istream & stream, MediaList & mediaList );

// Relational Operators

friend bool operator==( const MediaList & lhs, const MediaList & rhs );

friend bool operator

public:

// Types and Exceptions

enum class Position {TOP, BOTTOM};

struct InvalidInternalState_Ex : std::domain_error { using domain_error::domain_error; }; // Thrown if internal data structures become inconsistent with each other

struct CapacityExceeded_Ex : std::length_error { using length_error::length_error; }; // Thrown if more items are inserted than will fit

struct InvalidOffset_Ex : std::logic_error { using logic_error ::logic_error; }; // Thrown of inserting beyond current size

// Constructors, destructor, and assignment operators

MediaList(); // construct an empty media list

MediaList( const MediaList & other ); // construct a media list as a copy of another media list

MediaList( MediaList && other ); // construct a media list by taking the contents of another media list

MediaList & operator=( MediaList rhs ); // intentionally passed by value and not const ref

MediaList & operator=( MediaList && rhs );

MediaList ( const std::initializer_list & initList ); // constructs a media list from a braced list of media items

MediaList & operator+=( const std::initializer_list & rhs ); // concatenates a braced list of media items to this list

MediaList & operator+=( const MediaList & rhs ); // concatenates the rhs list to the end of this list

~MediaList();

// Queries

std::size_t size() const;

std::size_t find( const MediaItem & item ) const; // returns the (zero-based) offset from top of list

// returns the (zero-based) position of the item, size() if item not found

// Mutators

void insert( const MediaItem & item, Position position = Position::TOP ); // add the media item to the top (beginning) of the media list

void insert( const MediaItem & item, std::size_t offsetFromTop ); // inserts before the existing item currently at that offset

void remove( const MediaItem & item ); // no change occurs if item not found

void remove( std::size_t offsetFromTop ); // no change occurs if (zero-based) offsetFromTop >= size()

void moveToTop( const MediaItem & item );

void swap( MediaList & rhs ) noexcept; // exchange one media list with another

private:

// Helper functions

bool containersAreConsistant() const;

std::size_t media_sl_list_size() const; // std::forward_list doesn't maintain size, so calculate it on demand

// Instance Attributes

std::size_t _media_array_size = 0; // std::array's size is constant so manage that attributes ourself

std::array _media_array;

std::vector _media_vector;

std::list _media_dl_list;

std::forward_list _media_sl_list;

};

// Relational Operators

bool operator==( const MediaList & lhs, const MediaList & rhs );

bool operator!=( const MediaList & lhs, const MediaList & rhs );

bool operator

bool operator

bool operator> ( const MediaList & lhs, const MediaList & rhs );

bool operator>=( const MediaList & lhs, const MediaList & rhs );

Groceryltem GroceryList Public: Groceryltem() movie Title(): string director(): string studioName(): string run Time(): int (+Mutators) Public: GroceryList() find(): size_t insert(): void move To Top(): void operator+=(): GroceryList& remove(): void size(): size_t Private: _movie Title: string director: string _studioName: string _run Time: int Private: media_array: array _media_array_size: size_t media_dl_list: list _media_sl_list: forward_list media_vector: vector // Calculate the size of the singly linked list on demand std::size_t Medialist::media_sl_list_size() const { //////// TO-DO //// ////// III /// Some implementations of a singly linked list maintain the size (number of elements in the list). std:: forward_list does /// not. The size of singly linked list must be calculated on demand by walking the list from beginning to end counting the Il number of elements visited. The STL's std::distance() function does that, or you can write your own loop. }

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!