采用尾插法建立链表
typedef struct node标签:head,删除,--,age,next,链表,pa,link,new From: https://blog.51cto.com/u_15841666/5904152
{
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;
}