I'm making a delete function for a linked list, but it is not working correctly, it is causing massive problems when it reaches if statements. Can someone point me in the right direction please. (front is a global pointer)
Code:
void delEntry()
{
object *temp1=front;
object *temp2=front;
int delDate;
int delTime;
int i=1;
cout<<"date: ";
cin>>delDate;
cout<<"time: ";
cin>>delTime;
while(i!=0)
{
if(temp1==0)
{
cout<<"List Empty"<<"\n";
i=0;
}
else if(delDate==front->date)
{
if(front->time==delTime)
{
delete front;
front=0;
}
else
{
temp1=temp1->next;
temp2=temp1->next->next;
}
}
else if(delDate==temp2->date)
{
if(temp2->time==delTime)
{
temp1->next=temp2->next;
delete temp2;
temp1=temp2=0;
i=0;
}
else
{
temp1=temp1->next;
temp2=temp1->next->next;
}
}
else
{
temp1=temp1->next;
temp2=temp1->next->next;
}
}
}