//结构体形式
struct LinkList{
int value;
LinkLink* next;
}
//在链表尾增加节点
void addTail(LinkList** pHead,int value ){
LinkList* pNode = new LinkList();
pNode->value = value;
pNode->next = NULL;
if(*pHead==NULL){
*pHead = pNode ;
}else{
LinkList* pTemp = *pHead;
while(pTemp->next!=NULL){
pTemp = pTemp->next;
}
pTemp->next = pNode;
}
}
//删除一个值为value的节点
void deleteNode(LinkList** pHead,int value ){
if(pHead==NULL||*pHead==NULL||){
return;
}
LinkList* pToBeDelete = NULL;
if((*pHead)->value == value){
pToBeDelete = *pHead;
*pHead = (*pHead)->next;
}else{
LinkList* pNode = *pHead;
while(pNode!=NULL&&pNode->next->value!=value){
pNode = pNode->next;
}
while(pNode!=NULL&&pNode->next->value==value){
pToBeDelete = pNode->next;
pNode->next = pNode->next->next;
if(pToBeDelete != NULL){
delete pToBeDelete ;
pToBeDelete = NULL;
}
}
}
if(pToBeDelete!=NULL){
delete(pToBeDelete);
pToBeDelete = NULL;
}
}
链表节点的增加和删除--20150923
最新推荐文章于 2022-01-09 00:00:15 发布