?? insert.h
字號:
node *Insert(node *head, node *p)
{ // 把結(jié)點(diǎn)p插入到鏈表head中,使鏈表仍然保持升序
node *p1, *p2;
if(head==NULL) //如果插入前(原始鏈表)為空鏈表
{
head=p;
p->next=NULL;
return(head);
}
if( head->data >= p->data ) //插在鏈表首部
{
p->next = head;
head = p;
return(head);
}
p2=p1=head; // 插在鏈表中間或尾部
while( p2->next && (p2->data) < (p->data ) ) //查找待插入位置
{ p1=p2; p2 = p2->next; }
if( (p2->data) < (p->data) ) // 插在鏈表尾部
{
p2->next = p;
p->next = NULL;
}
else //插在鏈表中間, p2之前
{
p->next = p2;
p1->next = p;
}
return(head);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -