单链表学习课件.pptVIP

  • 0
  • 0
  • 约2.2千字
  • 约 22页
  • 2024-02-02 发布于浙江
  • 举报

第三章链接表;datalink;单链表中的插入;;第三种情况:在链表末尾插入

;intList::Insert(constintx,constinti){

ListNode*p=current;current=first;intk=0;

while(current!=NULLki-1)

{current=current→link;k++;}//找第i-1个结点

if(current==NULLfirst!=NULL){

cout“无效的插入位置!\n”;current=p;return0;}

ListNode*newnode=newListNode(x);

//创建新结点,数据为x,指针为NULL

return1;

}

;单链表中的删除(返回所删的结点值)

;intList::Remove(inti){

ListNode*q,*p=current

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档