SHARE
TWEET

Untitled

a guest Sep 20th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ///creare coada cu subprogram cu elem. nr nat
  2. ///afisarea nr din coada prime
  3. /// adaugarea in coada a nr max si apoi a nr min
  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.     ifstream f("list1.in");
  16.     nod*nou;
  17.     ///nr cunoscut de elem.
  18.     int i,n;
  19.     f>>n;
  20.     prim=new nod;
  21.     f>>prim->info;
  22.     prim->urm=NULL;
  23.     ultim=prim; ///in cazul in care coada are un elem si este si ultimul
  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.  
  34. }
  35. bool nrprim(int n)
  36. {
  37.     if(n<2) return false;
  38.     int d;
  39.     for(d=2;d<=n/2;d++)
  40.     if(n%d==0) return false;
  41.     return true;
  42. }
  43. int main()
  44. { nod*prim,*ultim,*p;
  45.  coada(prim,ultim);
  46.  for(p=prim;p!=NULL;p=p->urm)
  47.     if(nrprim(p->info)==true) cout<<p->info<<" ";
  48.  int max,min;
  49.  max=min=prim->info;
  50.  for(p=prim;p!=NULL;p=p->urm)
  51.  {
  52.      if(p->info<min) min=p->info;
  53.      if(p->info >max) max=p->info;
  54.  }
  55. nod*nou;
  56.  nou=new nod;
  57.  nou->info=max;
  58.  nou->urm=NULL;
  59.  ultim->urm=nou;
  60.  ultim=nou;
  61.  
  62.  nou=new nod;
  63.  nou->info=min;
  64.  nou->urm=NULL;
  65.  ultim->urm=nou;
  66.  ultim=nou;
  67.  cout<<endl;
  68.  for(p=prim;p!=NULL;p=p->urm)
  69.  {
  70.      cout<<p->info<<" ";
  71.  
  72.  }
  73.  ///sterg un element
  74. cout<<endl;
  75.  prim=prim->urm;
  76. for(p=prim;p!=NULL;p=p->urm)
  77.  {
  78.      cout<<p->info<<" ";
  79.  
  80.  
  81.  }
  82. }
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