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.


MeditList.hpp
#pragma once // include guard
#include
#include
#include
#include
#include
#include
#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
MediaList & operator+=( const std::initializer_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
std::vector
std::list
std::forward_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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
