Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct lista
- {
- string imie;
- int wiek;
- lista* next;
- };
- void DodajElement(string name, int age, lista*&glowa)
- {
- lista *NowyElListy, *tmp = glowa;
- NowyElListy = new lista;
- NowyElListy->imie = name;
- NowyElListy->wiek = age;
- NowyElListy->next = NULL;
- if(glowa==NULL)
- {
- glowa=NowyElListy;
- }
- else
- {
- while(tmp->next!=NULL)
- {
- tmp=tmp->next;
- }
- tmp->next = NowyElListy;
- }
- }
- void drukuj(lista* glowa)
- {
- cout<<"LISTA:\n";
- if(!glowa)
- {
- cout<<"BRAK ELEMENTÓW w LISCIE";
- }
- else
- {
- while(glowa)
- {
- cout<<glowa->wiek<<endl;
- glowa=glowa->next;
- }
- }
- }
- bool CzyPosortowana(lista* glowa)
- {
- while(glowa->next)
- {
- if(glowa->next->wiek < glowa->wiek)
- return 0;
- glowa=glowa->next;
- }
- return 1;
- }
- void DrugaTablica (lista* glowa, lista*&cel)
- {
- lista *tmp;
- while(glowa->next!=NULL)
- {
- if(glowa->next->wiek < glowa->wiek)
- {
- tmp = glowa->next;
- DodajElement(tmp->imie, tmp->wiek, cel);
- if(glowa->next->next==NULL)
- {
- delete tmp;
- }
- else
- {
- glowa->next=glowa->next->next;
- delete tmp;
- }
- }
- glowa=glowa->next;
- }
- }
- int main()
- {
- lista* glowa=NULL;
- lista* druga=NULL;
- DodajElement("Jan", 10, glowa);
- DodajElement("Andrzej", 20, glowa);
- DodajElement("Henryk", 5, glowa);
- DodajElement("Józef", 50, glowa);
- DodajElement("Dawid", 13, glowa);
- drukuj(glowa);
- DrugaTablica(glowa, druga);
- drukuj(druga);
- drukuj(glowa);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement