Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <ctime>
  5. using namespace std;
  6.  
  7. struct nodo {
  8. int info;
  9. nodo* next;
  10. nodo(int a = 0, nodo* b = 0)
  11. {
  12. info = a;
  13. next = b;
  14. }
  15. };
  16.  
  17. struct macro {
  18. nodo* macroInfo;
  19. macro* macroNext;
  20. macro(nodo* a = 0, macro* b = 0)
  21. {
  22. a = macroInfo;
  23. b = macroNext;
  24. }
  25. };
  26.  
  27. void stampa(nodo* a)
  28. {
  29. if (a) {
  30. cout << (a->info) << "->";
  31. stampa(a->next);
  32. }
  33. else {
  34. cout << "NULL" << endl;
  35. }
  36. }
  37.  
  38. void stampaMacro(macro* m)
  39. {
  40. if (m) {
  41. stampa(m->macroInfo);
  42. stampaMacro(m->macroNext);
  43. }
  44. else {
  45. cout << "FINE STAMPA MACRO" << endl;
  46. }
  47. }
  48.  
  49. int numeroCasuale()
  50. {
  51. return rand() % 10;
  52. }
  53.  
  54. nodo* creaLista(nodo* a, int numeroN)
  55. {
  56. if (numeroN == 0) {
  57. return NULL;
  58. }
  59. return a = new nodo(numeroCasuale(), creaLista(a, numeroN - 1));
  60. }
  61.  
  62. macro* creaMacro(macro* m, int d, int& input)
  63. {
  64. macro* copia=m;
  65.  
  66. while (input) {
  67. nodo* temp = new nodo(numeroCasuale(), NULL);
  68. macro* mtemp = new macro (temp,NULL);
  69. copia=mtemp;
  70. copia=mtemp->macroNext;
  71. input--;
  72. }
  73. return m;
  74. }
  75.  
  76. int main()
  77. {
  78. srand(time(NULL));
  79.  
  80. int input = 20; //quanti numeri dobbiamo leggere
  81. int d = 4; //quanto grande deve essere al massimo il nostro sistema
  82.  
  83. macro* m = new macro(NULL,NULL);
  84. m=creaMacro(m, d, input);
  85.  
  86. cout << "INIZIO STAMPA MACRO" << endl;
  87. stampaMacro(m);
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement