Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- const int N = 3;
- struct lista {
- int value;
- lista *next;
- };
- lista * add_value_at_the_beginning(lista *&a) {
- cout << "Podaj argumenty: " << endl;
- int val;
- cin >> val;
- lista *pomoc = new lista;
- pomoc->value = val;
- pomoc->next = a;
- return pomoc;
- }
- bool if_exists(lista *&a, int x) {
- lista *roboczy = new lista;
- *roboczy = *a;
- if(!a->next) {
- cout << "chuj kurwa jebac disa orka swiety mikolaj ";
- return false;
- }
- if (roboczy->value == x) {
- cout << "wartosc znaleziona" << endl;
- return true;
- } else {
- cout << "wartosc rozna: " << roboczy->value << " != " << x << endl;
- cout << "zmieniamy roboczy" << endl;
- roboczy = roboczy->next;
- cout << roboczy->value;
- return if_exists(roboczy, x);
- }
- }
- void check_if_exists(lista *a) {
- cout << "Podaj szukana wartosc" << endl;
- int x;
- cin >> x;
- cout << (if_exists(a, x) ? "istnieje" : "nie istnieje") << endl;
- }
- void count_all(lista *a) {
- int c = 0; // zerujemy licznik
- while (a) {
- c++;
- a = a->next;
- }
- cout << "wszystkich el. " << c << endl;
- }
- int main() {
- lista *m = nullptr;
- for (int i = 0; i < N; i++) {
- m = add_value_at_the_beginning(m);
- }
- check_if_exists(m);
- count_all(m);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement