diff --git a/lab3/UserTable.cc b/lab3/UserTable.cc index b52f0c6..7e0dd1e 100644 --- a/lab3/UserTable.cc +++ b/lab3/UserTable.cc @@ -27,6 +27,7 @@ UserTable::UserTable(const std::string &fname) : UserTable{} { void UserTable::addUser(const User &u) { // gör tabellen större vid behov ensureCapacity(n + 1); + // 1. Hitta rätt plats int pos{0}; 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 users[pos] = u; + + ++n; } User UserTable::find(int c) const { diff --git a/lab3/UserTableTest.cc b/lab3/UserTableTest.cc index 6ec3a19..98ccacf 100644 --- a/lab3/UserTableTest.cc +++ b/lab3/UserTableTest.cc @@ -18,4 +18,8 @@ int main() { assert(u3.getCardNbr() != u4.getCardNbr()); UserTable ut1 = UserTable("users.txt"); + + ut1.addUser(u3); + User us = ut1.find(1200); + assert(us != UserTable::user_not_found); }