- 论坛徽章:
- 0
|
#include<stdio.h>
#include<stdlib.h>
typedef struct list
{int age;
char name[20];
int id;
struct list* next;
}list;
void print_list(list* head)
{
while(head)
{
printf(“age=%d name=%s id=%d\n”,head->age,head->name,head->id);
head=head->next;}
}
void insert_order(list*head,int myage,char myname[],int myid)
{
List* newnode=(list*)malloc(sizeof(list));
newnode->age=myage;
newnode->id=myid;
strcpy(newnode->name,myname);
while(head->next&&head->next->id<myid)
head=head->next;
newnode->next=head->next;
head->next=newnode;
}
Int main(int argc,char**argv)
{ list*head=(list*)malloc(sizeof(list));
Head->next=NULL;
Head->id=-1;
Int id,age;
Char name[20];
Int i=0;
for(i=0;i<10;i++)
{
// Scanf(“%d %s %d”,&age,&name,&id);
age=random()%5+20;
id=random()%100;
Insert_order(head,age,name,id);
}
Print_list(head);
return 0;
}
说段错误 错在哪里啊 帮帮忙了 |
|