Я новичок в программировании и сейчас работаю над приложением, которое поможет управлять домашним бюджетом. Все данные хранятся в XML-файле. Для сортировки векторов по дате я реализовал алгоритм пузырьковой сортировки. Однако я сталкиваюсь с проблемами с неправильными результатами. Может ли кто-нибудь дать рекомендации по выявлению ошибки?
#include
#include
#include
#include "Markup.h"
using namespace std;
class income{
int userId;
int amount;
int itemId;
string item;
string date;
public:
void setUserId(int i) {userId = i;}
void setAmount(int a) {amount = a;}
void setItemId(int i ) {itemId = i;} // Corrected function name
void setDate(string d) {date = d;}
void setItem(string i) {item = i;}
int getUserId() {return userId;}
int getAmount() {return amount;}
int getItemId() {return itemId;}
string getItem() {return item;}
string getDate() {return date;}
};
bool returnOlderDate(string date1,string date2) {
int year1 = stoi(date1.substr(0,2));
int month1 = stoi(date1.substr(3,2)); // Corrected substring indices
int day1 = stoi(date1.substr(6,2)); // Corrected substring indices
int year2 = stoi(date2.substr(0,2));
int month2 = stoi(date2.substr(3,2)); // Corrected substring indices
int day2 = stoi(date2.substr(6,2)); // Corrected substring indices
if (year1 != year2) {
return year1 < year2;
}
if (month1 != month2) {
return month1 < month2;
}
return day1 < day2;
}
void sortVector(vector &incomes) {
int n = incomes.size();
for (int i = 0; i < n - 1; ++i) {
for (int j = 0; j < n - i - 1; ++j) {
if (returnOlderDate(incomes[j].getDate(), incomes[j + 1].getDate())) {
swap(incomes[j], incomes[j + 1]);
} else {
}
}
}
}
vector LoadIncome() {
CMarkup xml;
vector incomes;
bool fileExists = xml.Load("income.xml");
if(!fileExists) {
cout
Подробнее здесь: https://stackoverflow.com/questions/784 ... -algorithm
Векторная сортировка с использованием алгоритма пузырьковой сортировки ⇐ C++
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Программа пузырьковой сортировки не сортирует массив, а вводит новое значение [закрыто]
Anonymous » » в форуме C++ - 0 Ответы
- 43 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Программа пузырьковой сортировки не сортирует массив, а вводит новое значение
Anonymous » » в форуме C++ - 0 Ответы
- 44 Просмотры
-
Последнее сообщение Anonymous
-