链表(部分)

于指定位置插入
告诉指定位置
创建新节点
posFrontNode
posNode

posFrontNode->next=newNode;
newNode->next=posNode;

struct Node*headNode:操作的是哪个链表
int data:新节点数据
int posData:指定位置

void insertByAppoin(struct nodeheadNode,int data, int posData)
{
struct Node
posFrontNode=headNode;
struct Node*posNode=headNode->next;
移动的节点不为NULL,且当前节点中元素不等于插入的元素
while(posNode!=NULL&&posNode->data!=posData)
{

posFrontNode=posNode;
posNode=posFrontNode->next;
分析posNode状态
if(posNode==NULL)
{
    printf("未找到指定位置,无法插入!\n")
  }
  else
  {
  struct Node*newNode=createNode(data)
  posFrontNode->next=newNode;
  newNode->net=posNode;
  posFrontNode->next;
  }

}
int main()
{
insertByAppoin(list,-100,-1);
return 0;
}

void deleteNodeByHead(struct Node)
{
struct Node*nextNode=headNode->next;
if(nextNode==NULL)
{
printf("链表为空,无法删除);
return
}
headNode->next=nextNode->next;
free(nextNode);
}

int main()
{

deleteNodeByHead(list);
printList(list);

}

需要把删除节点的上一节点置空

void deleteNodeByTail(struct NodeheadNode)
{
struct Node
tailNode=headNode->next;尾节点
struct Node*tailFront=headNode;尾节点前面节点
while(tailNode->next!=NULL)
{

tailFrontNode=tailNode;
tailNode=tailFrontNode->next;

}
}
删除操作一定要判断是否为NULL
在尾节点 nextNode=NULL;置空处理

指定位置删除
void deleteByAppoin(struct Node* headNode,int posData)
{

}

if(posNode==NULL)
{
printf(“未找到指定位置,无法删除\n”);
}
else
{
posFrintNode->next=posNode->next;
free(posNode);
posNode=NULL;

}

int main()
{
deleteByAppoin(list,-100);
printList(list);
return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

忄离殇昔逝噬石心

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值