so I am basically trying to make a function that sorts a vector of a struct called tasks based on the task's priority. My program crashes whenever the given vector has two items or more dunno what's wrong with my code help! n thanks!
void sort_tasks(std::vector<tasks> &tasks_list)
{
if(!tasks_list.empty()){
bool result = false;
do
{
int counter = 0;
for(std::vector<tasks>::iterator i = tasks_list.begin(); i != tasks_list.end(); i++)
{
if(counter < tasks_list.size())
{
auto j = i++;
if(i->task_priority < j->task_priority) {
auto temp = *j;
*j = *i;
*i = temp;
if(!result) {
result = true;
}
}
}
counter++;
}
} while(result);
}
}
std::sort? It will be much easier and more efficient than bubble sort.iis "pointing" to the last element in the vector. When you then doi++where will it "point"?