linked list help please.
From: fighterman (fighterman_at_u.net)
Date: 03/31/04
- Next message: Dan Moos: "Re: what is wrong with this statement???"
- Previous message: SaltPeter: "Re: [C++] Initialization lists with array"
- Next in thread: lallous: "Re: linked list help please."
- Reply: lallous: "Re: linked list help please."
- Reply: John G.E: "Re: linked list help please."
- Reply: B. v Ingen Schenau: "Re: linked list help please."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 30 Mar 2004 22:26:06 -0600
I have a class
template <typename T>
class node
{
public:
T nodevalue; //store value
node<T> *next;
node(){next=NULL;}
node( T value, node<T> * ptr = NULL): nodevalue(value),next(ptr)
{}
};
this is insertrear function to insert node at the back of the linked list
template <typename T>
void insertrear( T value, node<T> * ptr)
{
node<T> *curr = *ptr;
node<T> * temp= new node<T>(value);
if(curr=NULL)
{
temp->next=curr;
curr=temp;
}
else{
while(curr->next!=NULL)
{
curr=curr->next;
}
temp->next=curr->next;
curr->next=temp;
}
delete temp;
}
And in the main function
int main()
{
node<int> *head;
for (int i=9; i>=0; i--)
insertrear( i , head);
return 0;
}
the problem is why when i run it, there is an pop up window said debug
error, run time check #3, head is using without defined.
I think when I declare head it will call the default constructor which is
next = NULL
what am I doing wrong?
- Next message: Dan Moos: "Re: what is wrong with this statement???"
- Previous message: SaltPeter: "Re: [C++] Initialization lists with array"
- Next in thread: lallous: "Re: linked list help please."
- Reply: lallous: "Re: linked list help please."
- Reply: John G.E: "Re: linked list help please."
- Reply: B. v Ingen Schenau: "Re: linked list help please."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]