Advertisement
wilk_maciej

LISTY

Mar 19th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. using namespace std;
  4.  
  5. // OBIEKT LISTA                                                                                                             DONE
  6. // operator wejscia dodaje 1 element, wyjscia wypisuje wszystkie el     NOT DONE
  7. // konstruktor, destruktor, konstruktor kopiujący                                          NOT DONE
  8. // + do listy dopisuje na końcu drógą                                                                    NOT DONE
  9. // =, ==, !=                                                                                                                    NOT DONE
  10. class List;
  11. class Element;
  12.  
  13. class Element{
  14.   friend ostream & operator<< (ostream & s1, List & o1);
  15.   friend istream & operator>>(istream & s1, List & o1);
  16.  
  17.  
  18.     public:
  19.     int war;
  20.     class Element *next;
  21.  
  22.     Element(int wart){
  23.         war = wart;
  24.         next= NULL;
  25.     }
  26. };
  27.  
  28. class List{
  29.  
  30.   friend ostream & operator<< (ostream & s1, List & o1);
  31.   friend istream & operator>>(istream & s1, List & o1);
  32.  
  33.     class Element *pierwszy;
  34.  
  35.     public:
  36.   List(){
  37.     pierwszy=NULL;
  38.   }
  39.  
  40.     ~List(){
  41.         while (pierwszy!=NULL){
  42.             if (pierwszy->next != NULL){
  43.                 class Element *nowy=pierwszy->next;
  44.                 delete pierwszy;
  45.                 pierwszy = nowy;
  46.             }
  47.             else{
  48.                 delete pierwszy;
  49.             }
  50.         }
  51.     }
  52.  
  53.     List(int war){
  54.         pierwszy = new class Element(war);
  55.     }
  56.  
  57. };
  58.  
  59.  
  60.  
  61. ostream & operator<< (ostream & s1, List & o1){
  62.   if (o1.pierwszy!=NULL){
  63.  
  64.   }
  65.   return s1;
  66. }
  67.  
  68.  
  69. istream & operator>>(istream & s1, List & o1){
  70.     int zmienna;
  71.     s1>>zmienna;
  72.     Element dodaj(zmienna);
  73.  
  74.   if (o1.pierwszy == NULL){
  75.         o1.pierwszy = &dodaj;
  76.     }
  77.     else{
  78.         class Element *nowy;
  79.             nowy=o1.pierwszy->next;
  80.         while (nowy->next != NULL){
  81.             nowy=nowy->next;
  82.         }
  83.         nowy->next=&dodaj;
  84.   }
  85.   return s1;
  86. }
  87.  
  88. int main(){
  89.     List lista;
  90.     Element zm(3);
  91.     cin >> lista;
  92.     return 0;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement