Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- #include <stdio.h>
- #include <ctime>
- using namespace std;
- struct nodo {
- int info;
- nodo* next;
- nodo(int a = 0, nodo* b = 0)
- {
- info = a;
- next = b;
- }
- };
- struct macro {
- nodo* macroInfo;
- macro* macroNext;
- macro(nodo* a = 0, macro* b = 0)
- {
- a = macroInfo;
- b = macroNext;
- }
- };
- void stampa(nodo* a)
- {
- if (a) {
- cout << (a->info) << "->";
- stampa(a->next);
- }
- else {
- cout << "NULL" << endl;
- }
- }
- void stampaMacro(macro* m)
- {
- if (m) {
- stampa(m->macroInfo);
- stampaMacro(m->macroNext);
- }
- else {
- cout << "FINE STAMPA MACRO" << endl;
- }
- }
- int numeroCasuale()
- {
- return rand() % 10;
- }
- nodo* creaLista(nodo* a, int numeroN)
- {
- if (numeroN == 0) {
- return NULL;
- }
- return a = new nodo(numeroCasuale(), creaLista(a, numeroN - 1));
- }
- macro* creaMacro(macro* m, int d, int& input)
- {
- macro* copia=m;
- while (input) {
- nodo* temp = new nodo(numeroCasuale(), NULL);
- macro* mtemp = new macro (temp,NULL);
- copia=mtemp;
- copia=mtemp->macroNext;
- input--;
- }
- return m;
- }
- int main()
- {
- srand(time(NULL));
- int input = 20; //quanti numeri dobbiamo leggere
- int d = 4; //quanto grande deve essere al massimo il nostro sistema
- macro* m = new macro(NULL,NULL);
- m=creaMacro(m, d, input);
- cout << "INIZIO STAMPA MACRO" << endl;
- stampaMacro(m);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement