I have a list, having nodes with only int an a pointer to the next node.
I want to make my list 2 way (meaning that i need to add one more pointer to the previous node).
This is my try for one way
And this is my try for two way listCode:struct AkeraiosStruct { int Value; AkeraiosStruct * next; } AkeraiosStruct; void insert_at_end (AkeraiosStruct * * ptraddr, int v) /* Insert v as last element of list *ptraddr */ { AkeraiosStruct * templist; templist = * ptraddr; while (*ptraddr != NULL) /* Go to end of list */ ptraddr = &((*ptraddr)->next);/* Prepare what we need to change */ *ptraddr = malloc(sizeof(struct AkeraiosStruct)); /* Space for new node */ (*ptraddr)->Value = v; /* Put value */ (*ptraddr)->next = NULL; /* There is no next element */ } void insert_at_start(AkeraiosStruct * *ptraddr, int v) /* Insert v as first element of list *ptraddr */ { AkeraiosStruct * templist; templist = *ptraddr; /* Save current start of list */ *ptraddr = malloc(sizeof(struct AkeraiosStruct)); /* Space for new node */ (*ptraddr)->Value = v; /* Put value */ (*ptraddr)->next = templist; /* Next element is former first */ }
But i can't modify insert_at_start/end in order to add the prev pointer.Code:struct AkeraiosStruct { int Value; AkeraiosStruct * next; AkeraiosStruct * prev; } AkeraiosStruct;



LinkBack URL
About LinkBacks




