This commit is contained in:
Mikołaj Rosa 2022-05-09 16:35:26 +02:00
parent 36072aeff8
commit 8aa47ad5b8
1 changed files with 19 additions and 2 deletions

View File

@ -15,9 +15,14 @@ int main() {
//demo_lista(); //demo_lista();
list<char> lista{ 'a','l','f','c' }; list<char> lista{ 'a','l','f','c' };
list<char>::iterator it = ListSearch(lista, 'g'); /*list<char>::iterator it = ListSearch(lista, 'g');
if (it == lista.end()) cout << "Nie znaleziono"; if (it == lista.end()) cout << "Nie znaleziono";
else cout << *it; else cout << *it;*/
auto print_char = [](const char& n) { cout << n << ' '; };
for_each(lista.begin(), lista.end(), print_char); cout << endl;
cout << (deleteNode(lista, 2) ? "Usunieto" : "Nie usunieto") << endl;
for_each(lista.begin(), lista.end(), print_char); cout << endl;
} }
void demo_lista() { void demo_lista() {
@ -67,4 +72,16 @@ list<char>::iterator ListSearch(list<char>& lista, char znak) {
} }
return it; return it;
}
bool deleteNode(list<char>& lista, int numer) {
if (lista.size() < numer || numer < 1) return false;
list<char>::iterator it;
int i = 1;
for (it = lista.begin(); i < numer; it++, i++);
lista.erase(it);
return true;
} }