I'm trying to make a function that lets me pass an index and a string and will insert the string at that index in the linkedlist... any help would be appreciated
Code:typedef struct node { char* value; struct node* next; } LinkedList; void llAddAtIndex(LinkedList** ll, char* value, int index) { LinkedList* newNode =(LinkedList*)malloc(sizeof(LinkedList)); newNode->value = value; LinkedList* prevNode = NULL; LinkedList p; p = ????? for(int i = 0; i < index; i++){ prevNode = p; p = p->next; } if (prevNode) { prevNode->next = newNode; newNode->next = p; } else { head = newNode; newNode->next = p; } }



2Likes
LinkBack URL
About LinkBacks



