void DeleteElemt(Node* head, int i, Elemt* e)
{
if(i<1 || i>head->data)
{
cout << "Error, Out of list, please choose the input i ";
*e = -1;
cout <<(*e)<<endl;
return;
}
Node* temp = head->right;
int j=1;
while (j<i && temp != NULL)
{
temp = temp->right;
j++;
}
Node* left = temp->left;
Node* right = temp->right;
left->right = right;
if(right != NULL)
{
right->left = left;
}
*e = temp->data;
cout<<"Delete the Node e: "<<(*e)<<endl;
delete temp;
head->data = head->data-1;
}
这段代码的目的时删除双向链表中的指定结点,但是运行的结果确是删除了指定结点之前的所有结点. 求指点一下 |