Advertisement
fcamuso

Corso recupero C++ - video 26

Dec 6th, 2022
1,183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.75 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct Calciatore {
  6.   string cognome="";
  7.   int goalSegnati=0;
  8.  
  9.   Calciatore *next = nullptr;
  10. };
  11.  
  12. void ins_testa(Calciatore* &il, Calciatore* nuovo)
  13. {
  14.    nuovo->next = il;
  15.    il = nuovo;
  16. }
  17.  
  18.  
  19. int main()
  20. {
  21.   Calciatore *il = nullptr;
  22.   Calciatore *nuovo = nullptr;
  23.   do {
  24.  
  25.     //creiamo un nodo
  26.     nuovo = new Calciatore;
  27.  
  28.     cout << "Inserire il cognome (stop per uscire): ";
  29.     cin >> nuovo->cognome;
  30.  
  31.     if (nuovo->cognome !="stop")
  32.     {
  33.       cout << "Goal segnati da questo calciatore: ";
  34.       cin >> nuovo->goalSegnati;
  35.  
  36.       ins_testa(il, nuovo);
  37.     }
  38.  
  39.   } while (nuovo->cognome!="stop");
  40.  
  41.   cout << il->cognome << " - " << il->next->cognome << endl;
  42.  
  43.     return 0;
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement