SHARE
TWEET

Untitled

a guest Sep 20th, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ///creearea unei cozi cu subpr. cu elem nr naturale
  2. ///afisarea nr din coada prime
  3. ///adaugarea in coada a nr max si apoi nr minim
  4. ///afisare coada
  5. #include<iostream>
  6. #include<fstream>
  7. using namespace std;
  8. struct nod
  9. {
  10.     int info;
  11.     nod* urm;
  12. };
  13. void coada(nod*&prim,nod*&ultim )
  14. {
  15.     nod *nou;
  16.     ///nr cunoscut de elem.
  17.     int n,i;
  18.     ifstream f("lista1.in");
  19.     f>>n;
  20.     prim=new nod;
  21.     f>>prim->info;
  22.     prim->urm=NULL;
  23.     ultim=prim;
  24.     for(i=2; i<=n; i++)
  25.     {
  26.         nou=new nod;
  27.         f>>nou->info;
  28.         nou->urm=NULL;
  29.         ultim->urm=nou;
  30.         ultim=nou;
  31.     }
  32. }
  33. bool nrprim(int n)
  34. {
  35.     if(n<2)
  36.         return false;
  37.     int d;
  38.     for(d=2; d<=n/2; d++)
  39.         if(n%d==0)
  40.             return false ;
  41.     return true;
  42. }
  43. int main()
  44. {
  45.     nod *prim,*p, *nou;
  46.     nod *ultim;
  47.     coada(prim,ultim);
  48.     for(p=prim; p!=NULL; p=p->urm)
  49.         if(nrprim(p->info)==true)
  50.             cout<<p->info<<" ";
  51.     int maxi,mini;
  52.     maxi=mini=prim->info;
  53.     for(p=prim; p; p=p->urm)
  54.     {
  55.         if(p->info<mini)
  56.             mini=p->info;
  57.         if(p->info>maxi)
  58.             maxi=p->info;
  59.     }
  60.     nou=new nod;
  61.     nou->info=maxi;
  62.     nou->urm=NULL;
  63.     ultim->urm=nou;
  64.     ultim=nou;
  65.  
  66.     nou=new nod;
  67.     nou->info=mini;
  68.     nou->urm=NULL;
  69.     ultim->urm=nou;
  70.     ultim=nou;
  71.     cout<<endl;
  72.     for(p=prim;p;p=p->urm)
  73.     cout<<p->info<<" ";
  74.     ///sterg un element (primu)
  75.     prim=prim->urm;
  76.     cout<<endl;
  77.      for(p=prim;p;p=p->urm)
  78.     cout<<p->info<<" ";
  79. }
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top