I was curious, and am not a C guy, so I did this
#include
struct doubleLink
{
struct doubleLink *previous;
int value;
struct doubleLink *next;
};
typedef struct doubleLink doubleLink;
void insertDoubleLink (struct doubleLink *newDoubleLink, struct doubleLink *doubleLinkBefore)
{
newDoubleLink->next = doubleLinkBefore->next;
newDoubleLink->previous = doubleLinkBefore;
doubleLinkBefore->next = newDoubleLink;
}
int main()
{
doubleLink head = { NULL, 0, NULL };
doubleLink link1 = { NULL, 1, NULL };
doubleLink link2 = { NULL, 2, NULL };
doubleLink link3 = { NULL, 3, NULL };
doubleLink newPointer = { NULL, 9001, NULL };
head.next = &link1;
link1.previous = &head;
link1.next = &link2;
link2.previous = &link1;
link2.next = &link3;
link3.previous = &link2;
doubleLink *listPointer;
doubleLink *np;
doubleLink *n3;
np = &newPointer;
n3 = &link2;
listPointer = &head;
insertDoubleLink(np, n3);
printf("Values of the list after insertion:\n");
while (listPointer != (struct doubleLink *) 0)
{
printf("%i ", listPointer->value);
listPointer = listPointer->next;
}
printf("\n");
}
and it seems to work perfectly fine.
I don't know what the rest of your code looks like, but this part seems functional.
I also don't understand the point of casting the '0' literal to a doubleLink pointer.