I can't understand why my newNode is becoming NULL. Should I be setting newNode = to something else?
/** Add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted. */
void addAtIndex(int index, int val) {
int curr_index = 0;
Node *newNode;
newNode->data = val;
Node *curr = front;
curr->prev = front;
Node *previous = front;
Node *back = NULL;
while (curr->next != NULL){
previous = curr;
curr = curr->next;
curr->prev = previous;
}
back = curr;
curr = front;
while (curr != NULL){
if (index = curr_index){
curr->prev = newNode;
newNode->next = curr;
newNode->prev = curr->prev;
curr = curr->next;
} else {
curr = curr->next;
curr_index++;
}
}
if (index > curr_index){
newNode->next = NULL;
newNode->prev = back;
back = newNode;
}
}
/** Delete the index-th node in the linked list, if the index is valid. */
void deleteAtIndex(int index) {
}