Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Klasa lista
- 1.obiekt to lista
- 2. << wypisuje wszystkie elementy, >> dodaje na koniec listy
- 3.konstr :) , dekonstr :) (nie rekurencyjnie bo zlozonosc niefajna), konstr kopiujacy :)
- 4. operatoty +, =, ==, !=
- */
- #include <iostream>
- using namespace std;
- class LISTA;
- class EL {
- friend class LISTA;
- friend ostream & operator<< (ostream &s1, LISTA & o1);
- friend istream & operator>> (istream &s1, LISTA &o1);
- int wartosc;
- class EL *next;
- };
- class LISTA {
- class EL *head;
- public:
- LISTA(){
- head=NULL;
- }
- LISTA(class LISTA &o1){
- if(o1.head==NULL) return;
- auto *nowy = new EL;
- nowy->wartosc=o1.head->wartosc;
- EL *temp=o1.head;
- EL *prev=nowy;
- head=nowy;
- temp=temp->next;
- while (temp!=NULL){
- EL *elemencik=new EL;
- prev->next=elemencik;
- prev=elemencik;
- temp=temp->next;
- }
- }
- ~LISTA(){
- while(head!=NULL){
- class EL *toDel;
- toDel=head;
- head=head->next;
- delete toDel;
- }
- }
- friend ostream & operator<< (ostream &s1, LISTA & o1);
- friend istream & operator>> (istream &s1, LISTA &o1);
- LISTA operator =(const class LISTA &o1){
- if (o1.head==NULL) return *this;
- auto *nowy = new EL;
- nowy->wartosc=o1.head->wartosc;
- EL *temp=o1.head;
- EL *prev=nowy;
- head=nowy;
- temp=temp->next;
- while(temp!=NULL){
- auto *elemencik=new EL;
- elemencik->wartosc=temp->wartosc;
- prev->next=elemencik;
- prev=elemencik;
- temp=temp->next;
- }
- prev->next=NULL;
- return *this;
- }
- LISTA & operator + (LISTA &o1){
- static LISTA temp;
- if (this->head==NULL && o1.head==NULL)
- return temp;
- EL *current = new EL;
- EL *node;
- EL *i = this->head;
- EL *j = o1.head;
- current->wartosc=i->wartosc;
- temp.head=current;
- while (i->next!=NULL){
- node=new EL;
- current->next=node;
- i=i->next;
- node->wartosc=i->wartosc;
- current=node;
- }
- node=new EL;
- node->wartosc=j->wartosc;
- current->next=node;
- while (j!=NULL){
- node=new EL;
- current->next=node;
- node->wartosc=j->wartosc;
- current=node;
- j=j->next;
- }
- return temp;
- }
- bool operator == (const class LISTA &o1){
- EL *temp1=this->head;
- EL *temp2=o1.head;
- int flaga=0;
- while(true){
- if (temp1==NULL) flaga+=1;
- if (temp2==NULL) flaga+=1;
- if (flaga==1) return false;
- else if (flaga==2) return true;
- if (temp1->wartosc!=temp2->wartosc) return false;
- temp1=temp1->next;
- temp2=temp2->next;
- }
- }
- bool operator != (const class LISTA &o1){
- EL *temp1=this->head;
- EL *temp2=o1.head;
- int flaga=0;
- while (true){
- if (temp1==NULL) flaga+=1;
- if (temp2==NULL) flaga+=1;
- if (flaga==1) return true;
- if (flaga==2) return false;
- if(temp1->wartosc==temp2->wartosc) return false;
- }
- }
- };
- ostream &operator<< (ostream &s1, LISTA &o1){
- EL *temp=o1.head;
- while(temp!=NULL){
- s1 << temp->wartosc<<" ";
- temp=temp->next;
- }
- return s1;
- }
- istream &operator>> (istream &s1, LISTA &o1){
- auto *element = new EL;
- s1 >> element->wartosc;
- if(o1.head==NULL) {
- o1.head = element;
- o1.head->next=NULL;
- return s1;
- }
- EL *n=o1.head;
- while(n->next!=NULL){
- n = n->next;
- }
- n->next = element;
- element->next = NULL;
- return s1;
- }
- int main (){
- LISTA zm1,zm2,zm3;
- cin>>zm1>>zm1>>zm1;
- zm2=zm1;
- cout<<zm2<<endl;
- if(zm1==zm2) cout<<"Tak"<<endl;
- else cout<<"Nie"<<endl;
- if(zm1!=zm2) cout<<"Tak2"<<endl;
- else cout<<"Nie2"<<endl;
- cin>>zm1;
- zm3=zm1+zm2;
- cout<<zm3;
- return 0;
- }
Add Comment
Please, Sign In to add comment