Advertisement
icatalin

tema 30.4

Apr 29th, 2015
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. cu nr din fisierul date.in creati 2 liste, prima in care adaugati nr. pare si a doua cu nr. impare. afisati pe cate o linie continutul lor
  2.  
  3. #include <fstream>
  4. #include <iostream>
  5. using namespace std;
  6. ifstream f("date.in");
  7. ofstream g("date.out");
  8. struct nod{
  9.     int info;
  10.     nod *adr;
  11. };
  12. nod *prim;
  13. nod *prim1;
  14. void creare()
  15. {
  16.     nod *p,*nou,*p1,*nou1;
  17.     int y;
  18.     while(f>>y)
  19.     {
  20.         if(prim==NULL||prim1==NULL)
  21.           {
  22.  
  23.             if(prim==NULL&&y%2==0)
  24.             {
  25.                 prim= new nod;
  26.                 prim->info=y;
  27.                 p=prim;
  28.             }
  29.             if(prim1==NULL&&y%2==1)
  30.             {
  31.                 prim1= new nod;
  32.                 prim1->info=y;
  33.                 p1=prim1;
  34.             }
  35.           }
  36.         else
  37.         {
  38.          if(y%2==0)
  39.          {nou=new nod;
  40.          nou->info=y;
  41.          p->adr=nou;
  42.          p=nou;
  43.          }
  44.          if(y%2==1)
  45.          {
  46.              nou1=new nod;
  47.              nou1->info=y;
  48.              p1->adr=nou1;
  49.              p1=nou1;
  50.          }
  51.         }
  52. }
  53.         p->adr=NULL;
  54.         p1->adr=NULL;
  55. }
  56. void parcurgere()
  57. {
  58.  nod *p=prim;
  59.  nod *p1=prim1;
  60.  while(p)
  61.  {
  62.         cout<<p->info<<" ";
  63.         p=p->adr;
  64.  }
  65.  cout<<'\n';
  66.  while(p1)
  67.  {
  68.      cout<<p1->info<<" ";
  69.      p1=p1->adr;
  70.  }
  71. }
  72. int main()
  73. {
  74.     creare();
  75.     parcurgere();
  76.      return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement