Insert Node at specific Index
C / C++ / MFC
1
Posts
1
Posters
0
Views
1
Watching
-
Hello Friends I am creating Insert function which is adding nodes to end of List but I want to Insert at specific Index. Any Ideas? Here is the Code :
void Insert(Node** apList, Node* apNode, int aIndex)
{
Node* tmp = NULL;
int len = 0;
while((*apList) != NULL)
{
tmp = (*apList);
apList = &((*apList)->next);
len++;} (\*apList)= (struct Node\*)malloc(sizeof(struct Node)); (\*apList)->num = apNode->num; (\*apList)->next = NULL; if(tmp) tmp->next = (\*apList);
}
How can I insert at aIndex ? regards Y