I have this exercise for my class, I have a struct with "monster types", I need to dynamically allocate each monster from array, then I need to enter monster name and his type, sort by name monsters I introduced, and print them, and finally I need tot deallocate memory. Please help me. This is a part from my code.
int main()
{
cout << "How many monsters do you want?: " << endl;
int length;
cin >> length;
Monster* miniMonsters = new Monster[length];
for (int i = 0; i < length ; ++i)
{
miniMonsters=new Monster[i];
}
enterMonster (miniMonsters , length);
bubbleSort(miniMonsters, length);
printMonster(miniMonsters, length);
for (int i = 0; i < length ; ++i)
{
delete[] miniMonsters[i];
}
delete[] miniMonsters;
miniMonsters = 0;
return 0;
}
Aucun commentaire:
Enregistrer un commentaire