Advertisement
Guest User

Untitled

a guest
Jan 28th, 2015
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.54 KB | None | 0 0
  1. /*napisać funkcję, która dla listy zaczynającej się pod jakimś adresem i zawierającej dane książek (autor, tytuł, liczba stron)
  2. a)usuwa książkę autora, podanego jako argument funkcji,
  3. b)drukuję listę pozostałych książek,
  4. c)drukuje dane najkrótszych książek,
  5. d)zwraca dane 1. książki na liście*/
  6.  
  7. #include <iostream>
  8.  
  9. using namespace std;
  10.  
  11. struct  Ksia{
  12.     string autor, tytul;
  13.     int strony;
  14.     Ksia *next;
  15. };
  16.  
  17. Ksia f(Ksia *&pl, string autor){
  18.     if(pl==NULL){return;}
  19.     Ksia *pop=new Ksia;
  20.     if (pl->autor==autor){
  21.         Ksia *tmp=new Ksia;
  22.         tmp=pl;
  23.         pl=pl->next;
  24.         delete tmp;
  25.     }else {
  26.         pop=pl;
  27.         while (pop->next->autor!=autor&&pop->next!=NULL){
  28.             pop=pop->next;
  29.         }
  30.         if(pop->next->autor==autor){
  31.             Ksia *akt=new Ksia;
  32.             akt=pop->next;
  33.             pop->next=akt->next;
  34.             delete akt;
  35.         }
  36.     }
  37.     pop=pl;
  38.     while (pop!=NULL){
  39.         cout<<pop->autor<<pop->tytul<<pop->strony<<endl;
  40.         pop=pop->next;
  41.     }
  42.     int min = pl->strony;
  43.     pop=pl;
  44.     while (pop!=NULL){
  45.         if (pop->strony<min){
  46.             min=pop->strony;
  47.         }
  48.         pop=pop->next;
  49.     }
  50.     pop=pl;
  51.     while (pop!=NULL){
  52.         if (pop->strony==min){
  53.             cout<<pop->autor<<pop->tytul<<pop->strony<<endl;
  54.         }
  55.         pop=pop->next;
  56.     }
  57.     Ksia dane;
  58.     dane.autor=pl->autor;
  59.     dane.tytul=pl->tytul;
  60.     dane.strony=pl->strony;
  61.     dane.next=pl->next;
  62.     return dane;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement