Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct nod
- {
- int h;
- nod* leg;
- };
- int main()
- {
- int n, a, i;
- nod* prim, *p, *q, *r;
- cout<<"Nr de elevi: ";
- cin>>n;
- prim=new nod;
- prim->h=INT_MAX;
- prim->leg=NULL;
- for(int i=1; i<=n; i++)
- {
- cout<<"Introduceti inaltimea: "; cin>>a;
- q=new nod;
- q->h=a;
- if(a<prim->h)
- {
- q->leg=prim;
- prim=q;
- }
- else{
- p=prim;
- while(a>=(p->h))
- {
- r=p;
- p=p->leg;
- }
- q->leg=p;
- r->leg=q;
- }
- }
- cout<<"Sirul sortat este: ";
- p=prim;
- for(i=1; i<=n; i++)
- {
- cout<<p->h<<" ";
- p=p->leg;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment