void insert(struct node *H,int p)
{
struct node *pr=H;
struct node node;
node=(struct node)malloc(sizeof(struct node));
while(pr->next ->x<p)
{
pr=pr->next;
}
node->next =pr->next ;
node->x =p;
pr->next =node;
}
void insert(struct node *H,int p)
{
struct node *pr=H;
struct node node;
node=(struct node)malloc(sizeof(struct node));
while(pr->next ->x<p)
{
pr=pr->next;
}
node->next =pr->next ;
node->x =p;
pr->next =node;
}
malloc有问题:
应该是struct node* node = (struct node*)malloc(sizeof(struct node));
而且还需要判断是否为NULL
void insert(struct node* H, int p)
{
struct node* pr = H;
struct node* node = (struct node*)malloc(sizeof(struct node));
while (pr->next && pr->next->x < p)
{
pr = pr->next;
}
node->next = pr->next;
node->x = p;
pr->next = node;
}