SHARE
TWEET

ASD Pb 15 liste pare impare

madalinaradu May 26th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /** p15 liste pare si impare*/
  2. #include<iostream>
  3. using namespace std;
  4.  
  5. class Lista;
  6.  
  7. class Nod {
  8. private:
  9.     int info;
  10.     Nod *next;
  11. public:
  12.     Nod(int info=0, Nod *next=NULL) {
  13.         this->info=info;
  14.         this->next=next;
  15.     }
  16.     int getInfo() {
  17.         return info;
  18.     }
  19.     friend class Lista;
  20. };
  21.  
  22. class Lista {
  23. private:
  24.     Nod *prim;
  25.     Nod *ultim;
  26. public:
  27.     Lista() {
  28.         prim=ultim=NULL;
  29.     }
  30.     void adaugareInceput(int info);
  31.     void adaugareSfarsit(int info);
  32.     void afisare();
  33.  
  34. };
  35.  
  36. void Lista:: adaugareInceput(int info) {
  37.     Nod *p=new Nod(info);
  38.     if(prim==NULL) {
  39.         prim=ultim=p;
  40.     } else {
  41.         p->next=prim;
  42.         prim=p;
  43.     }
  44. }
  45. void Lista::adaugareSfarsit(int info){
  46.     Nod *p=new Nod(info);
  47.     if(prim==NULL){
  48.         prim=ultim=p;
  49.     }else{
  50.         p->next=NULL;
  51.         ultim->next=p;
  52.         ultim=p;
  53.     }
  54. }
  55.  
  56. void Lista:: afisare() {
  57.     Nod *p=prim;
  58.     cout<<"[";
  59.     while(p!=NULL) {
  60.         cout<<p->info<<"  ";
  61.         p=p->next;
  62.     }
  63.     cout<<"]"<<endl;
  64. }
  65.  
  66. int main() {
  67.     int n=0;/// n = info
  68.     Lista lista,pare,impare;
  69.     cout<<"Dati n:";
  70.     cin>>n;
  71.     while(n!=-1){
  72.         if(n%2==0){
  73.             pare.adaugareInceput(n);
  74.             lista.adaugareInceput(n);
  75.         }else{
  76.             impare.adaugareInceput(n);
  77.             lista.adaugareInceput(n);
  78.         }
  79.          cout<<"Dati n:";
  80.         cin>>n;
  81.     }
  82.     cout<<"Lista integrala: ";
  83.     lista.afisare();
  84.     cout<<"Lista pare: ";
  85.     pare.afisare();
  86.     cout<<"Lista impare: ";
  87.     impare.afisare();
  88.     return 0;
  89. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top