I'm working with linked Lists (using pointers).
In a memory reserve function (using new) as long as% co_of%
In another function I release all the memory (with delete) and according to the project statement I should be able to generate a Lista == NULL
but after using delete List is different from NULL.
I exemplify it with the following code, where I ask for memory for a first node and then for the second iteration as nuevo_nodo
I release the memory with delete, but for the third iteration the list is not equal to null, so I I wonder if I have to initialize List to NULL after using delete
#include <iostream>
#include <cstdlib>
using namespace std;
struct Nodo {
int numero;
Nodo *Siguiente;
};
int main(){
Nodo *Lista = NULL;
for (int i=0; i<3;i++){
if( Lista==NULL ) {
cout<<"\nAgregar nodo."<<endl;
cout<<"Lista: "<<Lista<<endl;
Lista= new Nodo;
cout<<"Lista: "<<Lista<<endl;
} else {
cout<<"\nEliminar Nodo."<<endl;
cout<<"Lista: "<<Lista<<endl;
delete Lista;
cout<<"Lista: "<<Lista<<endl;
}
}
system("pause");
return 0;
}
I wonder if you would have to manually initialize List in NULL even after using delete, and why does this happen?