Question
The program runs and works just fine, except that in main class - case 3 ,I don't know how to call the void ScoresList::removeT(GameEntry *&targetNode)
The program runs and works just fine, except that in main class - case 3 ,I don't know how to call the "void ScoresList::removeT(GameEntry *&targetNode)" , please help me call the function and declare the targetNode in the main class,. (Please don't mind the other cases in switch and other functions in program,. I remove unnecessary parts of the program to shorten it's length. )
---
//P-3.4 Perform the previous project but use a doubly linked list. Moreover, your //implementation of remove(i) should make the fewest number of pointer //hops to get to the game entry at index i.
#include
using namespace std;
class GameEntry { private: string playerName; int playerScore; GameEntry *nodeNext; GameEntry *nodePrev; friend class ScoresList;
public: void setData(const string &name, int score) { playerName = name; playerScore = score; } void displays () { cout<<"Player's Name : "<< playerName< class ScoresList { private: GameEntry*headNode; void removeT(GameEntry *&targetNode); int scoreCounter; public: ScoresList(); void add(const GameEntry& e); void removeLast(); void printEntries(); }; ScoresList::ScoresList() // Constructor to assign values : headNode(NULL), scoreCounter(0) { } void ScoresList::removeLast() { GameEntry*tempNode; tempNode = headNode; while(tempNode->nodeNext->nodeNext != NULL) tempNode = tempNode->nodeNext; tempNode->nodeNext = NULL; scoreCounter--; } void ScoresList::add(const GameEntry& e) { GameEntry*buffNode = new GameEntry; buffNode->playerName = e.playerName; buffNode->playerScore = e.playerScore; buffNode->nodeNext = NULL; buffNode->nodePrev = NULL; if(headNode == NULL) { headNode = buffNode; scoreCounter++; } else { if(e.playerScore > headNode->playerScore) { buffNode -> nodeNext = headNode; headNode -> nodePrev = buffNode; headNode = buffNode; scoreCounter++; } else { GameEntry*tempNode ; tempNode = headNode; while(tempNode -> nodeNext != NULL) { if(tempNode -> playerScore > buffNode -> playerScore && buffNode -> playerScore >= tempNode -> nodeNext -> playerScore) { buffNode -> nodeNext = tempNode -> nodeNext; tempNode -> nodeNext -> nodePrev = buffNode; tempNode -> nodeNext = buffNode; buffNode -> nodePrev = tempNode; scoreCounter++; } tempNode = tempNode->nodeNext; } if(tempNode->playerScore >= buffNode-> playerScore) { cout<<" Sorry! The Score is insufficient to make it to the top 10."; } else { tempNode->playerName = e.playerName; tempNode->playerScore = e.playerScore; scoreCounter++; } } } if(scoreCounter >= 11) removeLast(); } void ScoresList::printEntries() { GameEntry *tempObj; tempObj = headNode; while(tempObj != NULL) { cout<< "\t\t\t\t\t\t\t" << tempObj->playerName<< "\t" << tempObj-> playerScore<< endl; tempObj = tempObj->nodeNext; } } void ScoresList::removeT(GameEntry *&targetNode) { if(targetNode == headNode) { headNode = headNode->nodeNext; if(headNode != NULL) headNode->nodePrev = NULL; } else if(targetNode->nodeNext == NULL) { targetNode->nodePrev->nodeNext = NULL; } else { targetNode->nodePrev->nodeNext = targetNode->nodeNext; targetNode->nodeNext->nodePrev = targetNode->nodePrev; } scoreCounter--; targetNode->nodeNext = NULL; targetNode->nodePrev = NULL; delete(targetNode); targetNode = NULL; } int main() { int choice, i; GameEntry GE; ScoresList sl; int a; string playerName; int playerScore; while (1) { cout< switch(choice) { case 1: cout< cout<<"\t\t\t\t\t | Top Scores |" < cout< case 2: cout<<"Remove Game Entry : "< cout< case 3: cout<<"Remove Game Entry using Target Node : "< // cin >> targetnode ; ? // sl.removeT(GE); ? cout< default: cout<
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