Bugfix 1
This commit is contained in:
parent
6130bdee66
commit
1dae994364
2 changed files with 7 additions and 0 deletions
|
@ -27,6 +27,7 @@ UserTable::UserTable(const std::string &fname) : UserTable{} {
|
||||||
void UserTable::addUser(const User &u) {
|
void UserTable::addUser(const User &u) {
|
||||||
// gör tabellen större vid behov
|
// gör tabellen större vid behov
|
||||||
ensureCapacity(n + 1);
|
ensureCapacity(n + 1);
|
||||||
|
|
||||||
// 1. Hitta rätt plats
|
// 1. Hitta rätt plats
|
||||||
int pos{0};
|
int pos{0};
|
||||||
while ((pos < n) && (users[pos].getCardNbr() < u.getCardNbr())) {
|
while ((pos < n) && (users[pos].getCardNbr() < u.getCardNbr())) {
|
||||||
|
@ -40,6 +41,8 @@ void UserTable::addUser(const User &u) {
|
||||||
|
|
||||||
// 3. stoppa in den nya användaren i luckan
|
// 3. stoppa in den nya användaren i luckan
|
||||||
users[pos] = u;
|
users[pos] = u;
|
||||||
|
|
||||||
|
++n;
|
||||||
}
|
}
|
||||||
|
|
||||||
User UserTable::find(int c) const {
|
User UserTable::find(int c) const {
|
||||||
|
|
|
@ -18,4 +18,8 @@ int main() {
|
||||||
assert(u3.getCardNbr() != u4.getCardNbr());
|
assert(u3.getCardNbr() != u4.getCardNbr());
|
||||||
|
|
||||||
UserTable ut1 = UserTable("users.txt");
|
UserTable ut1 = UserTable("users.txt");
|
||||||
|
|
||||||
|
ut1.addUser(u3);
|
||||||
|
User us = ut1.find(1200);
|
||||||
|
assert(us != UserTable::user_not_found);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue