章鱼龙怪图片大全:帮我看看这个函数在主函数怎样调用?(C++)

来源:百度文库 编辑:中科新闻网 时间:2024/05/12 04:20:59
include <iostream.h>
include <stdio.h>

struct node
{
int data;
node* next;
void Plus(node** headRef,int data);
void Display(node *head);
void Insert(node* &head,int data);
};
void Insert(node* &head,node* pio)
{
node* pio=new node;
pio->data;
node *bef,*cur;
bef=cur=head;
while(cur!=NULL)
{
if(cur->data >= pio->data)
break;
else{
bef=cur;
cur=cur->next;
}
}
if(cur==head)
{
pio->next=head;
head=pio;
}
else
{
bef->next=pio;
pio->next=cur;
}
}

void main()
{
head=NULL;
Plus(&head,3);
Plus(&head,2);
Plus(&head,1);
}

怎么调用Insert插入节点呢?
想不明白了,pio指针指向待插的数据,待插的数据在哪里来呢?

待插的数据当然自己声明呗。
比如:
node a;
a.data=100;
a.next=NULL;
Insert(head,&a);
或者
node *p=(node *)malloc(sizeof(node));
p->data=100;
p->next=NULL;
Insert(head,p);