This program actually have 4 function.
1)AddLast = to add a new node at the last of the list
2)FindNode = to find the desired node
3)DeleteNode = to delete the desired node
4)DisplayNode = display the listNow..my problems is with the AddLast function..
Before this I done with the AddFirst..Therefore,i try for this AddLast fuction.
I have already compile it using DevC compiler..no error listed..
But suddenly when the command prompt ask me to close the program..
I think maybe it became crash..Why???
I think the AddLast function is correct..
So,,can anyone help me to fix this crash things so that I can compile&run this code..
class List
{
public:
List(void) { head = NULL; } // constructor
~List(void); // destructor
bool IsEmpty() { return head == NULL; }
Node* AddLast(int index, double x);
int FindNode(double x);
int DeleteNode(double x);
void DisplayList(void);
private:
Node* head;
};
Node* List::AddLast(int index,double x) //please check for me with this AddLast function
{
if(index<0)
return NULL;
Node* currNode=head;
Node* newNode = new Node;
newNode->data = x;
if(head == NULL)
head = newNode;
else
{
currNode->next = head;
while(currNode->next !=NULL)
{
currNode = currNode->next;
}
currNode->next = newNode;
}
}
int main()
{
List n;
n.AddLast(22,7.0);
n.AddLast(44,5.0);
n.AddLast(66,3.0);
n.AddLast(88,6.0);
n.AddLast(99,4.0);
n.DisplayList();
system("pause");
return 0;
}