Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream.h>
- #include<conio.h>
- //Alocare dinamica|sterge + adaugare element la o pozitie
- #define n 5 //n noduri
- struct nod{
- int x;
- nod *next;
- };
- nod *p,*u;
- void ins(int val){
- nod *c,*a;
- c=p;
- if(p->x==val)
- {c=new nod;
- cout<<"INS";
- cin>>c->x;
- c->next=p;
- p=c;
- }else{
- while(c->next->x!=val &&c)
- c=c->next;
- a=new nod;
- cout<<"INS";
- cin>>a->x;
- a->next=c->next;
- c->next=a;
- }
- }
- void stergere(int val){
- nod *c,*a;
- c=p;
- if(p->x==val){
- a=p;
- p=p->next;
- delete a;
- }else{
- while(c->next->x!=val &&c)
- c=c->next;
- a=c->next;
- c->next=a->next;
- if(a==u) u=c;
- delete a;
- }
- }
- void add(){
- nod *c;
- if(!p){
- p=new nod;
- cout<<"X:";
- cin>>p->x;
- u=p;
- }else{
- c=new nod;
- cout<<"X:";
- cin>>c->x;
- u->next=c;
- u=c;
- }
- u->next=0;
- }
- void afis(){
- nod *c;
- c=p;
- while(c){
- cout<<c->x<<endl;
- c=c->next;
- }
- }
- void main(){
- for(int i=1;i<=n;i++)
- add( );
- ins(30);
- afis();
- stergere(70);
- afis();
- int x;
- cin>>x;
- }
Add Comment
Please, Sign In to add comment