Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct nod
- {
- int inf;
- nod *next;
- };
- nod *prim;
- void creare (nod *&prim)
- {
- int n,i;
- nod *p,*q;
- cout<<"Dati numarul de elemente: ";
- cin>>n;
- prim=new(nod);
- cout<<"Informatia 1= ";
- cin>>prim->inf;
- prim->next=NULL;
- p=prim;
- for (i=2; i<=n; i++)
- {
- q=new(nod);
- cout<<"Informatia "<<i<<"= ";
- cin>>q->inf;
- q->next=NULL;
- p->next=q;
- p=q;
- }
- }
- void add(nod* &prim)
- {
- nod *p,*q;
- if (prim==NULL)
- {
- prim=new(nod);
- cin>>prim->inf;
- prim->next=NULL;
- }
- else
- {
- p=prim;
- q=new(nod);
- while (p->next)
- p=p->next;
- q=new(nod);
- cin>>q->inf;
- q->next=NULL;
- p->next=q;
- }
- }
- void sterg(nod* &prim)
- {
- nod *q,*p;
- if (prim==NULL)
- cout<<"Nu ai ce sa stergi...";
- else
- {
- p=prim;
- prim=p->next;
- delete p;
- }
- }
- void afis(nod* &prim)
- {
- nod *p=prim;
- while (p)
- {
- cout<<p->inf<<" ";
- p=p->next;
- }
- cout<<endl;
- }
- int main()
- {
- creare(prim);
- afis(prim);
- add(prim);
- afis(prim);
- sterg(prim);
- afis(prim);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement