so u mean that the code that i have written is not correct....and i have modify my program more.
You didn't write any code for the splitAt method, so it correctly does nothing. Yes, you need more code. After looking at fanda's code above, I think it's missing something.
For example, create a list with one element, say 5. Split it at that element. That should break fanda's code. Look at the head pointer, before and after. Let <- be pPrev, -> be pNext, and <-> be two nodes pointing to each other with pPrev, and pNext respectively.
Before - NULL <- head <-> 5 -> NULL
After - NULL <- head -> NULL
-
NULL <- secondHead <-> 5 -> NULL
- Node* splitAt(const int nodeValue)
-
{
-
Node* pCursor = head;
-
while(pCursor != NULL)
-
{
-
if(pCursor->nData == nodeValue)
-
{ // if we found the split element
-
if(pCursor == pHead) // if we split at the head
-
pHead = NULL; // the head becomes null
-
pTail = pCursor->pPrev; // tail is the last node before split
-
return pCursor; // return pointer to new head
-
}
-
pCursor = pCursor->pNext; // else go to next node
-
}
-
return NULL; // did not find element
-
}