Hi guys, I am creating a 2D casual game and i encounter a problem.
The problem is that I have a highscore features that saves to a text file by storing the name and score
Now i wanted it to sort using bubblesort and structures. How can i achieve that?
Thanks.
#pragma once
class HighscoreSort
{
public:
HighscoreSort(void);
~HighscoreSort(void);
void bubbleSort(int data[], int length);
};
#include "HighscoreSort.h"
HighscoreSort::HighscoreSort(void)
{
}
HighscoreSort::~HighscoreSort(void)
{
}
void HighscoreSort::bubbleSort(int data[], int length)
{
for(int iter = 1; iter < length; iter++)
{
for(int index = 0; index < length - iter; index++)
{
if(data[index] < data[index+1])
{
//swap around
int temp = data[index];
data[index] = data[index+1];
data[index+1] = temp;
}
}
}
}
From what I know struct shld be using string name; string score; ???