Given the following code for storing Game entries in an arra

Given the following code for storing Game entries in an array, change the code to use a singly linked

list in place of the array.

class GameEntry a game score entry public: GameEntry (const string& n int s 0); //constructor string getName() const; get player name int getScore() const; get score private player\'s name string name; player\'s score int score; Game Entry: GameEntry(const string& n, int s) constructor name(n), score(s) accessors string Game Entry: getName() const return name; int GameEntry:getScore() const {return score; void Scores: add(const GameEntry& e) add a game entry int new Score e.getScore(); score to add the array is full if (numEntries max Entries) if (newScore entries[maxEntries-1].getScore()) not high enough ignore return

Solution

Comment: I have added the logic below. even provided the add and remove methods as per the logic you have written above. You may need to change certain syntax to run it properly. And you may need to change the return type of add and remove method to return scores object. All the best.

struct node
{
GameEntry data;
struct node *next;
}*head;

list::list()
{
date=NULL;
subject=NULL;
writing=NULL;
}

list::~list()
{
delete[]name;
delete[]score;
}
void add(GameEntry data, int loc)
{
int i;
struct node *temp,*left,*right;
right=head;
while(right->next != NULL)
{
GameEntry e = right->data;
if(data.score > e.score) {
left=right;
right=right->next;   
} else {
break;
}
}
temp=(struct node *)malloc(sizeof(struct node));
temp->data=new GameEntry(data.name, data.score);
left->next=temp;
left=temp;
left->next=right;
return;
}
int remove(int num)
{
int i;
struct node *temp,*left,*right;
right=head;
for(i=1;i<loc;i++)
{
left=right;
right=right->next;
}
if(right == head) {
head=right->next;
free(right);
return 1;
}else
{
left->next=right->next;
free(right);
return 1;
}
left->next=right->next;
left=temp;
left->next=right;
return;
}

Given the following code for storing Game entries in an array, change the code to use a singly linked list in place of the array. class GameEntry a game score e
Given the following code for storing Game entries in an array, change the code to use a singly linked list in place of the array. class GameEntry a game score e

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site