Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- typedef int T;
- typedef struct cell {
- T info;
- cell *next;
- } * list;
- int length(list l);
- void print(list l);
- list clear(list & l);
- int main() {
- list lista = new cell;
- list head = new cell;
- list aux = head;
- cout << "Numero rounds: ";
- int round;
- cin >> round;
- for (int i = 0; i < round; i++) {
- aux->info = i + 1;
- aux->next = lista;
- lista = aux;
- }
- aux->next = nullptr;
- /*
- aux = head;
- int n = 0;
- while ((aux != nullptr) && (n<round)){
- print(aux);
- n++;
- }
- cout << endl;*/
- aux = head;
- cout << length(aux);
- return 0;
- }
- //lunghezza di una lista
- int length(list l) {
- if (l) return length(l->next) + 1;
- else return 0;
- }
- //stampa una lista
- void print(list l) {
- if (l) {
- cout << l->info << " ";
- print(l->next);
- }
- }
- //cancella lista
- list clear(list & l) {
- if (l) {
- l->next = clear(l->next);
- delete l;
- }
- return nullptr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement