#include<stdio.h>
typedef struct Student{
int id;
Student *next;
}Stu, *Head;
void insert(Head &head){// 后插法
Stu* s = new Stu;
Head p = head;
while(p->next != NULL){
p = p->next;
}
int id;
printf("id\n");
scanf("%d",&id);
s->id = id;
p->next = s;
s->next = NULL;
printf("插入成功\n");
return;
}
void insert2(Head &head){// 前插法
Stu* s = new Stu;
Head p = head;
int id;
printf("id\n");
scanf("%d",&id);
s->id = id;
if(p->next == NULL){
p->next = s;
s->next = NULL;
}else{
s->next = p->next;
p->next = s;
}
printf("插入成功\n");
return;
}
void show(Head &head){// 显示链表
Head p = head->next;
while(p != NULL){
printf("%d ",p->id);
p = p->next;
}
printf("\n");
}
int main(){
Head head = new Stu;
head->next = NULL;
insert2(head);
insert2(head);
insert2(head);
show(head);
printf(" 成功");
return 0;
}