Advertisement
LiMIllusion

Untitled

Dec 19th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. struct nodo{
  4.   int inf;
  5.   struct nodo *next;
  6. };
  7.  
  8. void *crealista(struct nodo *testa1){
  9.   struct nodo *p;
  10.   testa1=NULL;
  11.   char r;
  12.   while(1) {
  13.     p= new nodo;
  14.     std::cout << "Inserisci valore" << '\n';
  15.     std::cin >> p->inf;
  16.     p->next=testa1;
  17.     testa1=p;
  18.     std::cout << "Vuoi aggiungere un altro elemento?" << '\n';
  19.     std::cin >> r;
  20.     if (r=='n'){
  21.       break;
  22.     }
  23.   }
  24. }
  25.  
  26. void *stampalista(struct nodo *testa1){
  27.   struct nodo *p;
  28.   p=testa1;
  29.   char r;
  30.   while(p->next!=NULL){
  31.     std::cout << p->inf << '\n';
  32.     p=p->next;
  33.   }
  34. }
  35.  
  36. int  main() {
  37.   struct nodo *testa;
  38.   crealista(testa);
  39.   stampalista(testa);
  40.  
  41.   return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement