Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int n, LISTA[105];
  6.  
  7. void createList()
  8. {
  9. cout<<"Nr de elemente ale listei: ";
  10. cin>>n;
  11. cout<<"Elementele listei: ";
  12. for(int i=1;i<=n;i++)
  13. cin>>LISTA[i];
  14. }
  15.  
  16. void coutList()
  17. {
  18. for(int i=1;i<=n;i++)
  19. cout<<LISTA[i]<<' ';
  20. }
  21.  
  22. void insertElement()
  23. {
  24. int p, e;
  25. cout<<"Pe ce pozitie sa se gaseasca noul element: ";
  26. cin>>p;
  27. cout<<"Ce element sa fie introdus: ";
  28. cin>>e;
  29. for(int i=p;i<=n;i++)
  30. LISTA[i+1]=LISTA[i];
  31. LISTA[p]=e;
  32. n++;
  33. }
  34.  
  35. void deleteElement()
  36. {
  37. int p;
  38. cout<<"Pozitia elementului care va fi eliminat: ";
  39. cin>>p;
  40. for(int i=p;i<=n;i++)
  41. LISTA[p]=LISTA[p+1];
  42. n--;
  43. }
  44.  
  45. void isVoid()
  46. {
  47. if(n==0)
  48. cout<<"Lista este vida";
  49. else
  50. cout<<"Lista este nevida";
  51. }
  52.  
  53. void isFull()
  54. {
  55. if(n==105)
  56. cout<<"Lista este plina";
  57. if(n<105)
  58. cout<<"Lista nu este plina";
  59. }
  60.  
  61. int main()
  62. {
  63. int b=0;
  64. int tasta;
  65. cout<<"1 pentru a crea o lista"<<'\n'<<"2 pentru a afisa lista"<<'\n'<<"3 pentru a insera un element"<<'\n'<<"4 pentru a sterge un element"<<'\n'<<"5 pentru a afisa daca lista este vida"<<'\n'<<"6 pentru a afisa deaca lista este goala"<<'\n'<<"7 pentru a opri programul"<<'\n';
  66. while(b==0)
  67. {
  68. cin>>tasta;
  69. switch(tasta)
  70. {
  71. case 1:createList();break;
  72. case 2:coutList();break;
  73. case 3:insertElement();break;
  74. case 4:deleteElement();break;
  75. case 5:isVoid();break;
  76. case 6:isFull();break;
  77. case 7:b=1;break;
  78. }
  79. }
  80. return 0;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement