Answered step by step
Verified Expert Solution
Question
1 Approved Answer
You will be building a linked list. there is something wrong with my insertafter function as i keep recieving this error: Tests that InsertAfter (
You will be building a linked list. there is something wrong with my insertafter function as i keep recieving this error: Tests that InsertAfter correctly inserts "All For You"s node after "Peg"s node
Returned unexpected error code
Build the PlaylistNode class per the following specifications.
Default constructor pt
Parameterized constructor pt
Public member functions
InsertAfter pt
SetNext Mutator pt
GetID Accessor
GetSongName Accessor
GetArtistName Accessor
GetSongLength Accessor
GetNext Accessor
PrintPlaylistNode
Private data members
string uniqueID Initialized to "none" in default constructor
string songName Initialized to "none" in default constructor
string artistName Initialized to "none" in default constructor
int songLength Initialized to in default constructor
PlaylistNode nextNod#include "Playlist.h
PlaylistNode::PlaylistNode
uniqueID "none";
songName "none";
artistName "none";
songLength ;
nextNodePtr ;
PlaylistNode::PlaylistNodeconst string& id const string& sname, const string& aname, int length
uniqueID id;
songName sname;
artistName aname;
songLength length;
nextNodePtr ;
void PlaylistNode::InsertAfterPlaylistNode ptr
thisSetNextptrGetNext;
ptrSetNextthis;
void PlaylistNode::SetNextPlaylistNode ptr
nextNodePtr ptr;
Playlist::Playlist
head tail nullptr;
void Playlist::AddSongconst string& id const string& sname, const string aname, int length
PlaylistNode temp new PlaylistNodeid sname, aname, length;
if head
head tail temp;
else
tempInsertAftertail;
tail temp;
bool Playlist::RemoveSongconst string& id
if head nullptr
cout "Playlist is empty" endl;
return false;
PlaylistNode curr head;
PlaylistNode prev nullptr;
while curr nullptr
if currGetID id
break;
prev curr;
curr currGetNext;
if curr nullptr
cout currGetSongName is not found" endl;
return false;
else
if prev nullptr
prevSetNextcurrGetNext;
else
head currGetNext;
if tail curr
tail prev;
cout currGetSongName removed." endl;
delete curr;
return true;
bool Playlist::ChangePositionint currPos, int newPos
if head nullptr
cout "Playlist is empty" endl;
return false;
PlaylistNode prev nullptr;
PlaylistNode curr head;
int pos;
if head nullptr head tail
return false;
for pos ; curr nullptr && pos currPos; pos
prev curr;
curr currGetNext;
if curr nullptr
string currentSong currGetSongName;
if prev nullptr
head currGetNext;
else
prevSetNextcurrGetNext;
if curr tail
tail prev;
PlaylistNode newCurr curr;
prev nullptr;
curr head;
for pos ; curr NULL && pos newPos; pos
prev curr;
curr currGetNext;
if prev nullptr
newCurrSetNexthead;
head newCurr;
else
newCurrInsertAfterprev;
if curr nullptr
tail newCurr;
cout currentSong moved to position newPos endl;
return true;
else
cout "Song's current position is invalid" endl;
return false;
void Playlist::SongsByArtistconst string& artistName const
if head nullptr
cout "Playlist is empty" endl;
else
PlaylistNode curr head;
int i ;
while curr nullptr
if currGetArtistName artistName
cout endl i endl;
currPrintPlaylistNode;
curr currGetNext;
i;
int Playlist::TotalTime const
int total ;
PlaylistNode curr head;
while curr nullptr
total currGetSongLength;
curr currGetNext;
return total;
void Playlist::PrintList const
if head nullptr
cout
Playlist is empty" endl;
else
PlaylistNode curr head;
int i ;
while curr nullptr
cout endl i endl;
currPePtr Initialized to in default constructor
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started