|
My program use a list like that :
//**************************************************
struct NODE
{
int mt[3][3];
int h, g, f;
NODE *Next;
};
struct List
{
NODE *Head;
NODE *Tail;
};
//****************And i get a new Node :
NODE GetNode(int A[3][3], int h, int g)
{
NODE *p=new NODE;
if (!p)
{
cout<<"Cannot create a new node";
return NULL;
}
// get the value for NODE
..........
//
p->h=h;
p->g=g;
p->f=g+h;
p->Next=NULL;
return p;
}
//************Then Insert a node after List like that :
NODE *InsertTail(List &LS, int A[3][3], int h, int g)
{
NODE *new_node = GetNode(A,h,g);
if (!new_node)
return NULL;
if (!LS.Head) //List is Empty
{
LS.Head=new_node;
LS.Head=LS.Tail;
}
else
{
LS.Tail->Next=new_node;
LS.Tail=new_node;
}
return new_node;
}
//******Let the List Empty:
void EmptyList(List &LS)
{
LS.Head=LS.Tail=NULL;
}
//*************************************************************
In my program, i have some functions that remove an element of the list and add a new element to the tail....
But if i can't InsertTail for the large times (about over 300 times). Why is it? I think After finished my GetNode or InsertTail function, the variable Node that i create with "new" keyword must be detroyed automatically right?
I really dont know about it.
Because after i use InsertTail, i remove alot of elements in it.
And my List never has more than 9 elements. Why my memory is full? (I receive the message : "cannot create a new node" that i type in the GetNode function )
How can i solve my problem with the large loop to use
InsertTail.
Please help me.
Thanks
John
|
|
|
|
|
|
|
// |