Commit 1a0fd5a9 authored by Florian Klemme's avatar Florian Klemme
Browse files

Stilistische Änderungen.

parent 22dea3aa
Pipeline #79 passed with stages
in 2 minutes and 4 seconds
......@@ -3,18 +3,14 @@
CppKlausur::CppKlausur(std::istream& in, std::ostream& out) : m_in(in), m_out(out) {}
void CppKlausur::run() {
while (true) {
int modus = 0;
int modus = 0;
m_in >> modus;
while (modus >= 1 && modus <= 3) {
Zahlen key = lese_zahlen();
if (modus == 1) einfuegemodus(key);
if (modus == 2) suchmodus(key);
if (modus == 3) loeschmodus(key);
m_in >> modus;
if (modus < 1 || modus > 3) {
return; // Beenden
} else {
Zahlen key = lese_zahlen();
if (modus == 1) einfuegemodus(key);
if (modus == 2) suchmodus(key);
if (modus == 3) loeschmodus(key);
}
}
}
......@@ -39,36 +35,36 @@ void CppKlausur::einfuegemodus(const Zahlen& key) {
}
void CppKlausur::suchmodus(const Zahlen& key) const {
if (m_forward.contains(key)) {
const String& value = m_forward.at(key);
m_out << value << ' ';
if (!m_forward.contains(key)) return;
auto& zahlen_liste = m_reverse.at(value);
m_out << zahlen_liste.size();
const String& value = m_forward.at(key);
m_out << value << ' ';
for (int i = 0; i < zahlen_liste.size(); ++i) {
m_out << '\n';
auto& zahlen = zahlen_liste[i];
for (int j = 0; j < zahlen.size(); ++j) {
if (j) m_out << ' ';
m_out << zahlen[j];
}
}
auto& zahlen_liste = m_reverse.at(value);
m_out << zahlen_liste.size();
for (int i = 0; i < zahlen_liste.size(); ++i) {
m_out << '\n';
auto& zahlen = zahlen_liste[i];
for (int j = 0; j < zahlen.size(); ++j) {
if (j) m_out << ' ';
m_out << zahlen[j];
}
}
m_out << '\n';
}
void CppKlausur::loeschmodus(const Zahlen& key) {
if (m_forward.contains(key)) {
const String& value = m_forward.at(key);
m_forward.erase(key);
if (!m_forward.contains(key)) return;
const String& value = m_forward.at(key);
m_forward.erase(key);
auto& zahlen_liste = m_reverse[value];
for (int i = 0; i < zahlen_liste.size(); ++i) {
if (zahlen_liste[i] == key) {
zahlen_liste.erase(i);
break; // sollte nur einmal vorkommen
}
auto& zahlen_liste = m_reverse[value];
for (int i = 0; i < zahlen_liste.size(); ++i) {
if (zahlen_liste[i] == key) {
zahlen_liste.erase(i);
break; // sollte nur einmal vorkommen
}
}
}
\ No newline at end of file
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment