采用尾插法建立链表
typedef struct node
{
int age;
struct node* next;
}link;
int main()
{
link* head = (link*)malloc(sizeof(link));
link* new, * tail;
tail = head;
int n, i;
scanf("%d", &n);
for (i = 0; i < n; i++)
{
new = (link*)malloc(sizeof(link));
new->age = i;
new->next = NULL;
tail->next = new;
tail=new;
}
link* p = head->next;
while(p)
{
printf("%d ", p->age);
p = p->next;
}
//删除数据data N
link* pa=NULL, * q = head;
pa = q->next;
int N = 0;
scanf("%d", &N);
while (pa && pa->age != N)
{
q = pa;
pa = pa->next;
}
q->next = pa->next;
p = head->next;
while (p)
{
printf("%d ", p->age);
p = p->next;
}
return 0;
}