Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4. using namespace std;
  5.  
  6. const int MAX=10;
  7. int coda[MAX];
  8. int fine;
  9.  
  10. struct nodo{
  11. string nome;
  12. nodo* succ
  13. };
  14.  
  15. void Svuotacoda();
  16. void Pop();
  17. void Push();
  18. void Scrivicoda();
  19. void Presentamenu();
  20. int menu();
  21.  
  22. nodo* testa;
  23.  
  24. int menu(){
  25. int selezione=0;
  26. do{
  27. cout<<endl;
  28. cout<<"1-svuota coda"<<endl;
  29. cout<<"2-estrai un dato"<<endl;
  30. cout<<"3.aggiungi un dato"<<endl;
  31. cout<<"4-scrivi coda"<<endl;
  32. cout<<"5-fine"<<endl;
  33. cout<<"qual è la selezione=?";
  34. cin>>selezione;
  35. cin.ignore();
  36. }while(selezione < 1 ||selezione > 5);
  37.  
  38. return menu;
  39. }
  40.  
  41.  
  42. void Svuotacoda()
  43. {
  44. fine=-1;
  45. cout<<"coda vuota"<<endl;
  46. }
  47.  
  48. void Pop()
  49. {
  50. nodo* p;
  51. if(fine==-1){
  52. cout<< " coda vuota. Nessun elemento estratto"<<endl;
  53. }else{
  54. cout<< "elemento estratto=" <<coda[0]<<endl;
  55. for(int i=1; i<=fine; i++){
  56. coda[i-1]=coda[i];
  57. fine=fine-1;
  58. }
  59. }
  60. delete testa;
  61. testa=p;
  62. }
  63.  
  64. void Push()
  65. {
  66. string dato;
  67. nodo* nuovo;
  68. int dato;
  69. if(fine==MAX-1){
  70. cout<<" coda piena. Nessun elemento inserito"<<endl;
  71. }else{
  72. cout<< "dato da inserire=";
  73. cin>>dato;
  74. nuovo= new nodo;
  75.  
  76. nuovo-nome=dato;
  77. nuovosucc=testa;
  78. testa=nuovo;
  79. }
  80. }
  81.  
  82. void Scrivicoda()
  83. {
  84. cout<<"inizio coda"<<endl;
  85. for(int i=0; i<=fine; i++){
  86. cout<<setw(5)<<coda[i];
  87. cout<<"fine coda"<<endl;
  88. }
  89. }
  90.  
  91. int main()
  92. {
  93. int scelta;
  94. do{
  95. do{
  96. Presentamenu();
  97. cout<<"inserisci la tua scelta";
  98. cin>>scelta;
  99. }while( scelta<1 || scelta>5);
  100. switch(scelta){
  101. case 1:
  102. Svuotacoda();
  103. break;
  104. case 2:
  105. Pop();
  106. break;
  107. case 3:
  108. Push();
  109. break;
  110. case 4:
  111. Scrivicoda();
  112. break;
  113. }
  114. }while(scelta!=5);
  115.  
  116. return 0;
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement