Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- #define NULL 0
- const int N = 3;
- struct lista{
- int value;
- lista *next;
- };
- void 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;
- *a=*pomoc;
- }
- bool if_exists(lista *a, int x){
- lista *roboczy = new lista;
- *roboczy=*a;
- while(roboczy!=NULL){
- if(roboczy->value==x){
- cout<<"wartosc znaleziona"<<endl;
- return true;
- } else{
- cout<<"wartosc rozna: " << roboczy->value << " != " << x << endl;
- int przerwa;
- cin>>przerwa;
- }
- cout<<"zmieniamy roboczy"<<endl;
- roboczy = roboczy->next;
- cout<<roboczy->value;
- }
- if(roboczy->value==x){
- cout<<"wartosc znaleziona"<<endl;
- return true;
- }
- return false;
- }
- 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 = new lista;
- for(int i = 0; i<N; i++){
- add_value_at_the_beginning(m);
- }
- check_if_exists(m);
- count_all(m);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement