problem with linklist

S

sunilsomanna

template<class T>
void TimerDLList<T>::addFirst(TimerItem<T>* const itemPtr)
{
// suppose itemPtr is not pointing to NULL

itemPtr->prev = (TimerItem<T>*) NULL;

head = (TimerItem<T>*)NULL;

if (tail == (TimerItem<T>*)NULL ) // nothing in the link list
{
tail = itemPtr;
itemPtr->next = (TimerItem<T>*) NULL;
}
else
{
itemPtr->next = head;
head->prev = itemPtr;
}

head = itemPtr;
}



there seems to be some problem in head->prev = itemPtr.
There seems to be some corrution at this point.
PLEASE HELP.......
seems like head->prev is accessing a wrong address.
 
T

Thomas Lumley

template<class T>
void TimerDLList<T>::addFirst(TimerItem<T>* const itemPtr)

Looks like C++ to me. You may want comp.lang.c++ or a platform-
specific newsgroup, but not comp.lang.c.

-thomas
 
J

Jens Thoms Toerring

template<class T>
void TimerDLList<T>::addFirst(TimerItem<T>* const itemPtr)

This looks lik C++, but this comp.lang.c, not comp.lang.c++.
{
// suppose itemPtr is not pointing to NULL
itemPtr->prev = (TimerItem<T>*) NULL;
head = (TimerItem<T>*)NULL;
if (tail == (TimerItem<T>*)NULL ) // nothing in the link list
{
tail = itemPtr;
itemPtr->next = (TimerItem<T>*) NULL;
}
else
{
itemPtr->next = head;
head->prev = itemPtr;
}
head = itemPtr;
}
there seems to be some problem in head->prev = itemPtr.

When you first set 'head' to NULL then you shouldn't be too
astonished when you can't dereference it later on...

Regards, Jens
 
M

Martin Ambuhl

template<class T>
void TimerDLList<T>::addFirst(TimerItem<T>* const itemPtr)

There are languages in which the above makes sense (C++ springs to
mind), but C is not one of them. If your question is about the
programming language C++, you might find an answer if you posted to a
C++ newsgroup. <is one of those. If it is some
other language, you will need to look for the appropriate newsgroup.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top