Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct lista{
- int info;
- int next;
- }l[100];
- int n,opt,x,pos;
- void creare ()
- {n=0;
- }
- void adaugare (int x)
- {l[n].info=x;
- l[n].next=n++;
- }
- void inserare (int x, int pos)
- {int i;
- for (i=n;i>pos;i--)
- {l[i].info=l[i-1].next+1;
- }
- l[pos].info=x;
- l[pos].next=pos+1;
- n++;
- }
- void stergere (int pos)
- {int i;
- for (i=pos;i<n-1;i++)
- {l[i].info=l[i+1].info;
- l[i].next=l[i-1].next-1;
- }
- n--;
- }
- void afisare ()
- {int i;
- for (i=0;i<n;i++)
- cout<<l[i].info<<" ";
- }
- int main ()
- {creare ();
- cout<<"0-Iesire; 1-Adaugare; 2-Inserare; 3-Sterge; 4-Afisare; Ce doriti sa faceti?";
- cin>>opt;
- switch (opt)
- {case 0 : break;
- case 1 : cout<<"Dati elementul: ";
- cin>>x; adaugare (x);
- break;
- case 2 : cout<<"Dati pozitia si elementul: ";
- cin>>pos>>x; inserare (x,pos);
- break;
- case 3 : cout<<"Dati pozitia: ";
- cin>>pos; stergere (pos);
- break;
- case 4 : afisare (); break;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement