Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cmath>
- using namespace std;
- int maxi;
- struct nod
- {
- int nr;
- nod *urm;
- };
- ifstream f("test.in");
- void creare(nod *&prim, nod *&ultim)
- {
- int n,i;
- nod *nou;
- f>>n;
- prim= new nod;
- f>>prim->nr;
- prim->urm=NULL;
- ultim=prim;
- for(i=2; i<=n; i++)
- {
- nou=new nod;
- f>>nou->nr;
- nou->urm=NULL;
- ultim->urm=nou;
- ultim=nou;
- }
- }
- void afisare(nod *prim)
- {
- nod *a;
- for(a=prim; a!=NULL; a=a->urm)
- cout<<a->nr<<" ";
- }
- void eliminare(nod *&prim)
- {
- nod *aux;
- aux=prim;
- prim=prim->urm;
- delete aux;
- }
- void adaugare(nod *&ultim)
- {
- nod *nou;
- nou=new nod;
- cin>>nou->nr;
- nou->urm=NULL;
- ultim->urm=nou;
- ultim=nou;
- }
- int patrat(int n)
- {
- int sq=sqrt(n);
- if(sq*sq==n)return 1;
- return 0;
- }
- void mapatrate(nod *prim)
- {
- nod *a;
- int s=0,c=0;
- for(a=prim; a!=NULL; a=a->urm)
- if(patrat(a->nr)==1)
- {
- c++;
- s=s+a->nr;
- }
- cout<<(float)s/c;
- }
- void maxim(int &n, nod *prim)
- {
- nod *a;
- for(a=prim; a!=NULL; a=a->urm)
- if(a->nr>n)n=a->nr;
- }
- void vecini(nod *prim)
- {
- nod *a;
- a=prim;
- while(a->urm!=NULL)
- {
- if(a->nr==maxi)
- cout<<a->urm->nr<<" ";
- if(a->urm->nr==maxi)
- cout<<a->nr<<" ";
- a=a->urm;
- }
- }
- int main()
- {
- nod *prim,*ultim;
- creare(prim,ultim);
- cout<<endl<<"coada: ";
- afisare(prim);
- cout<<endl<<endl;
- cout<<"Adaug ";
- adaugare(ultim);
- cout<<endl<<"coada: ";
- afisare(prim);
- cout<<endl<<endl;
- cout<<"sterg un element";
- eliminare(prim);
- cout<<endl<<endl<<"coada: ";
- afisare(prim);
- cout<<endl<<endl;
- cout<<"med arit a nr patrate este ";
- mapatrate(prim);
- cout<<endl<<endl;
- maxi=prim->nr;
- maxim(maxi,prim);
- cout<<"maximul este "<<maxi<<" si are vecinii ";
- vecini(prim);
- cout<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement