|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Senior Member
Iscritto dal: Oct 2006
Città: milano
Messaggi: 1439
|
[c++] probelma allocazione dinamica
dopo aver fatto lo stack in modo "fuffo" con un array sto provando a farlo dinamico senza array con strutture ma ho dei problemi..
Codice:
#include <iostream> using namespace std; struct Nodo { char dato; struct Nodo* next; } ; typedef struct Nodo* nodo; void menu(); void push(nodo nodoTesta); void pop(); void showStack(); int main() { int choose; nodo nodoTesta = NULL; menu(); do { cin >> choose; switch(choose) { case 1: push(nodoTesta); break; case 2: pop(); break; case 3: showStack(); break; case 4: break; } } while(choose != 4); cin.get(); return 0; } void menu() { cout << "1 - aggiungi un carattere nello stack." << endl; cout << "2 - estrai un carattere dallo stack." << endl; cout << "3 - visualizza lo stack." << endl; cout << "4 - esci." << endl; cout << "? "; } void push(nodo nodoTesta) { //nodo newNodo = new nodo; } void pop() { } void showStack() { } ![]() |
![]() |
![]() |
![]() |
#2 |
Senior Member
Iscritto dal: Oct 2007
Città: Padova
Messaggi: 4131
|
ho sbagliato
|
![]() |
![]() |
![]() |
#3 |
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
Sostituisci Nodo * a nodo e dimmi se ti torna.
La new di nodo torna un nodo * non un nodo ![]() |
![]() |
![]() |
![]() |
#4 |
Senior Member
Iscritto dal: Oct 2006
Città: milano
Messaggi: 1439
|
Codice:
#include <iostream> using namespace std; struct Nodo { char dato; struct Nodo* next; } ; //typedef struct Nodo* nodo; void menu(); void push(Nodo* nodoTesta); void pop(); void showStack(); int main() { int choose; Nodo* nodoTesta = NULL; menu(); do { cin >> choose; switch(choose) { case 1: push(nodoTesta); break; case 2: pop(); break; case 3: showStack(); break; case 4: break; } } while(choose != 4); cin.get(); return 0; } void menu() { cout << "1 - aggiungi un carattere nello stack." << endl; cout << "2 - estrai un carattere dallo stack." << endl; cout << "3 - visualizza lo stack." << endl; cout << "4 - esci." << endl; cout << "? "; } void push(Nodo* nodoTesta) { Nodo* newNodo = new Nodo; } void pop() { } void showStack() { } ![]() |
![]() |
![]() |
![]() |
#5 |
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
Dovresti fare:
nodo n = new Nodo; |
![]() |
![]() |
![]() |
#6 |
Senior Member
Iscritto dal: Oct 2006
Città: milano
Messaggi: 1439
|
giusto grazie
![]() |
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 00:27.