Need help with sorting Urgent ://
Apr 30, 2013 at 4:06am UTC
Ok so I did this project where I take in a date, vector int year, vector int month, vector int day and a vector string called appointment
thing is I suck at c++, so I didn't do it in a struct or a class. Just made a bunch of vector functions.
Now I am trying to organize my vectors so they all go together. Assuming the logic would be organize the year vector then bubble sort rest,... do same with month vector... then day vector
my problem now is
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
for (int j = 0; j<days.size() && j<months.size() && j<years.size() && j<appointments.size();++j)
{
temp1 = months[j];
temp2 = years[j];
temp3 = appointments[j];
temp4 = days[j];
for (int i = 1; i<years.size();++i)
{
if (years[i-1]> years[i]) //.erase[i] check years... months ... then days
{
years.push_back(years[i-1]);
months.push_back(temp1);
appointments.push_back(temp3);
days.push_back(temp4);
months.erase (months.begin()+0);
years.erase (years.begin()+0);
appointments.erase (appointments.begin()+0);
days.erase (days.begin()+0);
}
}
for (int i = 1; i<months.size();++i)
{
if (months[i-1]> months[i]) //.erase[i] check years... months ... then days
{
months.push_back(months[i-1]);
years.push_back(temp2);
appointments.push_back(temp3);
days.push_back(temp4);
months.erase (months.begin()+0);
years.erase (years.begin()+0);
appointments.erase (appointments.begin()+0);
days.erase (days.begin()+0);
}
}
for (int i = 1; i<days.size();++i)
{
if (days[i-1]> days[i]) //.erase[i] check years... months ... then days
{
days.push_back(days[i-1]);
months.push_back(temp1);
years.push_back(temp2);
appointments.push_back(temp3);
months.erase (months.begin()+0);
years.erase (years.begin()+0);
appointments.erase (appointments.begin()+0);
days.erase (days.begin()+0);
}
}
}
I am erasing the first vector, how do I erase the vector slot I push back not the first only?
Topic archived. No new replies allowed.