#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<math.h>
struct A {
int a;
struct A* next;
};
struct A * creat(struct A *head) {
struct A* p1,*p2;
p1 = (struct A*)malloc(sizeof(struct A));
p2 = (struct A*)malloc(sizeof(struct A));
head = NULL;
scanf("%d",&p1->a);
int n = 0;
while (p1->a!=0) {
if (n==0) {
head = p1;
}
else {
p2->next = p1;
p2 = p1;
p1 = (struct A*)malloc(sizeof(struct A));
scanf("%d", &p1->a);
}
n++;
}
p2->next = NULL;
return head;
}
struct A * insert(struct A *head,struct A *p){
struct A *p1,*p2;
p2=(struct A*)malloc(sizeof(struct A*));
p1=head;
while(p1->next!=NULL&&p->a>p1->a){
p2=p1;
p1=p1->next;
}
if(p1->next==NULL){
p1->next=p;
p->next=NULL;
}else{
p2->next=p;
p->next=p1;
}
return head;
}
struct A* del(struct A * head,int aa){
struct A * p1,*p2;
p1=head;
p2=(struct A *)malloc(sizeof(struct A));
while(p1->next!=NULL&&aa!=p1->a){
p2=p1;
p1=p1->next;
}
if(p1==head){
head=p1->next;
}else{
p2->next=p1->next;
}
return head;
}
void show(struct A *head) {
struct A* p = head;
do {
printf("%d ",p->a);
p = p->next;
} while (p!=NULL);
printf("\n");
}
int main() {
struct A *head= (struct A*)malloc(sizeof(struct A));
head=creat(head);
show(head);
struct A *p= (struct A*)malloc(sizeof(struct A));
p->a=33;
head=insert(head,p);
show(head);
head=del(head,33);
show(head);
}