Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct lista{
  5. int info;
  6. int next;
  7. }l[100];
  8.  
  9. int n,opt,x,pos;
  10. void creare ()
  11. {n=0;
  12. }
  13.  
  14. void adaugare (int x)
  15. {l[n].info=x;
  16. l[n].next=n++;
  17. }
  18.  
  19. void inserare (int x, int pos)
  20. {int i;
  21. for (i=n;i>pos;i--)
  22. {l[i].info=l[i-1].next+1;
  23. }
  24. l[pos].info=x;
  25. l[pos].next=pos+1;
  26. n++;
  27. }
  28.  
  29. void stergere (int pos)
  30. {int i;
  31. for (i=pos;i<n-1;i++)
  32. {l[i].info=l[i+1].info;
  33. l[i].next=l[i-1].next-1;
  34. }
  35. n--;
  36. }
  37. void afisare ()
  38. {int i;
  39. for (i=0;i<n;i++)
  40. cout<<l[i].info<<" ";
  41. }
  42.  
  43. int main ()
  44. {creare ();
  45. cout<<"0-Iesire; 1-Adaugare; 2-Inserare; 3-Sterge; 4-Afisare; Ce doriti sa faceti?";
  46. cin>>opt;
  47. switch (opt)
  48. {case 0 : break;
  49. case 1 : cout<<"Dati elementul: ";
  50. cin>>x; adaugare (x);
  51. break;
  52. case 2 : cout<<"Dati pozitia si elementul: ";
  53. cin>>pos>>x; inserare (x,pos);
  54. break;
  55. case 3 : cout<<"Dati pozitia: ";
  56. cin>>pos; stergere (pos);
  57. break;
  58. case 4 : afisare (); break;
  59. }
  60. return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement