Coz im lazy and i didn't want to write same code 8 times changing only one word i came up with this:
template <class type> void DeleteFromLinkedList(type * p, type * first_object)
{
if (p == 0) return;
if (p->prev == 0) //deleting first object
{
if (p->next != 0) p->next->prev = 0;
first_object = p->next;
delete p;
return;
}
if ( (p->prev != 0) && (p->next == 0) ) //last
p->prev->next = 0;
if ( (p->prev != 0) && (p->next != 0) )
{
p->prev->next = p->next;
p->next->prev = p->prev;
}
delete p;
}
however i have an issue with deleting first object in linked list, i try to delete it but it 'remains' moreover some of the information remains and first_object still points on memory that was 'deleted' [or at least half of the object was wipedout from the memory]
in example i have a personel structure
struct personel
{
char * name;
char * surname;
int nlen;
int slen;
unsigned char age;
etc
personel * next;
personel * prev;.
};
after deletion of first object of this linked list structure
i am able to lets say read surname (its exactly the same) but name and other info is gone, also it should point on the other personel.;
what the heck