SHARE
TWEET

BunaSiua

a guest May 22nd, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. struct punct
  7. {
  8.     int x,y;
  9. };
  10.  
  11. struct nod
  12. {
  13.     punct info;
  14.     nod *urm;
  15. };
  16.  
  17. void Initializare(nod *&prim, nod *&ultim)
  18. {
  19.     prim=ultim=NULL;
  20. }
  21.  
  22. void Citire(nod *&prim,nod *&ultim)
  23. {
  24.     punct x;
  25.     cout<<"x=";cin>>x.x;
  26.     cout<<"y=";cin>>x.y;
  27.     if(prim==NULL)
  28.     {
  29.         prim= new nod;
  30.         prim->info=x;
  31.         prim->urm=NULL;
  32.         ultim=prim;
  33.     }
  34.     else
  35.     {
  36.         nod *p=new nod;
  37.         p->info=x;
  38.         p->urm=NULL;
  39.         ultim->urm=p;
  40.         ultim=p;
  41.     }
  42. }
  43.  
  44. float Distanta(punct a, punct b)
  45. {
  46.     return sqrt(float(b.x-a.x)*(b.x-a.x)+float(b.y-a.y)*(b.y-a.y));
  47. }
  48.  
  49. void Stergere(nod *&prim, nod *&ultim, nod *&p)
  50. {
  51.     if(p->urm==ultim)
  52.     {
  53.         p->urm=NULL;
  54.         delete ultim;
  55.         ultim=p;
  56.     }
  57.     else
  58.     {
  59.         nod *q=p->urm;
  60.         p->urm=q->urm;
  61.         delete q;
  62.     }
  63. }
  64.  
  65. void Verificare(nod *&prim, nod *&ultim)
  66. {
  67.     for(nod *p=prim; p!=ultim; p=p->urm)
  68.         for(nod *q=p->urm; q; q=q->urm)
  69.             if(Distanta(p->info,q->info)>2.00)
  70.                 Stergere(prim,ultim,p);
  71. }
  72.  
  73. void Afisare(nod *&prim, nod *&ultim)
  74. {
  75.     for(nod *p=prim; p; p=p->urm)
  76.         cout<<p->info.x<<"  "<<p->info.y<<endl;
  77. }
  78.  
  79. int main()
  80. {
  81.     int n;
  82.     nod *prim,*ultim;
  83.     Initializare(prim,ultim);
  84.     cout<<"Numarul de noduri: ";
  85.     cin>>n;
  86.     for(int i=0; i<n; i++)
  87.         Citire(prim,ultim);
  88.     Verificare(prim,ultim);
  89.     Afisare(prim,ultim);
  90.     return 0;
  91. }
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