Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- /**
- Liste liniare simplu inlantuite=LLSI
- 1. adaugare la final =adaugare
- 2. adaugare in fata primului nod = adaugareInainte
- 3. afisarea liste =afisare
- */
- struct nod
- {
- int info;
- nod *urm;
- };
- nod *p;
- void adaugare(nod * & p , int x)
- {
- ///adaugare nod la final
- nod* q=new nod;
- q->info=x;
- q->urm=NULL;
- if(p==0)///lista vida
- p=q;
- else
- {
- nod* u;
- for(u=p; u->urm!=NULL; u=u->urm);
- u->urm=q;///leg elemente existe de noul nod
- }
- }
- void adaugareInainte(nod * & p , int x)
- {
- nod*q=new nod;
- q->info=x;
- q->urm=p;
- p=q;
- }
- void Creare(nod*&p)
- {
- ifstream fin("lista.in");
- int x;
- while(fin>>x)
- ///adaugare(p,x);
- adaugareInainte(p,x);
- fin.close();
- }
- void afisare(nod*p)
- {
- for(nod *q=p;q; q=q->urm)
- cout<<q->info<<" ";
- cout<<"\n";
- }
- int main()
- {
- Creare(p);
- afisare(p);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement