|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Senior Member
Iscritto dal: Nov 2003
Città: MILANO
Messaggi: 1095
|
Liste!!!!!!!!!!!!!!!!!!!!!
ho un problema:nessu ha un programma in c++ che allohi e deallochi una lista?
anche con la progettazione . ciao |
![]() |
![]() |
![]() |
#2 |
Senior Member
Iscritto dal: Apr 2002
Città: Vigevano(PV)
Messaggi: 2124
|
Codice:
#include <iostream> #include <string> #include <cmath> #include <cstdio> using namespace std; #ifndef LIST_H #define LIST_H // Liste bilaterale struct lista { int data; lista *next; lista(int Data, lista *Next) { Next = next; Data = data; } }; void inizializza(lista ls); void aggiungi(lista* &ls, int n); lista *cerca(lista *ls, int n); void print(lista *ls); void inizializza(lista *ls) { ls = new lista(0, NULL); } void aggiungi(lista* &ls, int n) { if(ls == NULL){ // primo elemento ls->data = n; ls->next = NULL; return; } while(ls->next != NULL) // ultimo elemento ls = ls->next; ls->next = new lista(n, NULL); } lista *cerca(lista *ls, int n) { if(ls == 0) return 0; lista* p = ls; while( (p->next != NULL) && (p->data != n) ){ p = p->next; } return p; } void print(lista *ls) { lista *p = ls; while(p->next != NULL){ cout << p->data; p = p->next; } } #endif
__________________
Gnu/Linux User ![]() |
![]() |
![]() |
![]() |
#3 |
Senior Member
Iscritto dal: Nov 2003
Città: MILANO
Messaggi: 1095
|
grazie
ma non hai la progettazione a blocchi? |
![]() |
![]() |
![]() |
#4 | |
Senior Member
Iscritto dal: Apr 2002
Città: Vigevano(PV)
Messaggi: 2124
|
Quote:
__________________
Gnu/Linux User ![]() |
|
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 21:18.