Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. #define NULL 0
  5. const int N = 3;
  6.  
  7. struct lista{
  8. int value;
  9. lista *next;
  10. };
  11.  
  12. void add_value_at_the_beginning(lista *&a){
  13. cout<<"Podaj argumenty: "<<endl;
  14. int val;
  15. cin>> val;
  16. lista *pomoc = new lista;
  17. pomoc->value = val;
  18. pomoc->next = a;
  19. *a=*pomoc;
  20. }
  21.  
  22. bool if_exists(lista *a, int x){
  23. lista *roboczy = new lista;
  24. *roboczy=*a;
  25.  
  26. while(roboczy!=NULL){
  27. if(roboczy->value==x){
  28. cout<<"wartosc znaleziona"<<endl;
  29. return true;
  30. } else{
  31. cout<<"wartosc rozna: " << roboczy->value << " != " << x << endl;
  32. int przerwa;
  33. cin>>przerwa;
  34. }
  35. cout<<"zmieniamy roboczy"<<endl;
  36. roboczy = roboczy->next;
  37. cout<<roboczy->value;
  38. }
  39. if(roboczy->value==x){
  40. cout<<"wartosc znaleziona"<<endl;
  41. return true;
  42. }
  43. return false;
  44. }
  45.  
  46. void check_if_exists(lista *a){
  47. cout << "Podaj szukana wartosc" << endl;
  48. int x;
  49. cin >> x;
  50. cout<<(if_exists(a, x) ? "istnieje" : "nie istnieje") << endl;
  51. }
  52.  
  53. void count_all(lista *a){
  54. int c = 0; // zerujemy licznik
  55. while(a)
  56. {
  57. c++;
  58. a = a->next;
  59. }
  60. cout<<"wszystkich el. " << c << endl;
  61. }
  62.  
  63. int main()
  64. {
  65. lista *m = new lista;
  66. for(int i = 0; i<N; i++){
  67. add_value_at_the_beginning(m);
  68. }
  69. check_if_exists(m);
  70. count_all(m);
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement