#include <stdio.h> #include <stdlib.h> typedef int DataType; struct node{ DataType data; struct node *next; }; typedef struct node* PNode; PNode creat_node(); PNode insert_node(PNode node,int num); void delectLowerThanZero_node(PNode node); void printf_node(PNode node); int main() { PNode node=creat_node(); int n,m; scanf("%d",&n); for (int i = 0; i < n; ++i) { scanf("%d",&m); insert_node(node,m); } printf("after insert: "); printf_node(node); delectLowerThanZero_node(node); printf("after delect: "); printf_node(node); return 0; } PNode creat_node(){ PNode p; p=(PNode)malloc(sizeof(struct node)); if(p!=NULL){ p->next=NULL; return p; } return printf("creat fail!!!"); } PNode insert_node(PNode node,int num){ if(node==NULL)return printf("insert fail!!!"); PNode p=(PNode)malloc(sizeof(struct node)); if(p!=NULL){ p->data=num; p->next=NULL; } PNode q=node; while(q->next!=NULL){ q=q->next; } q->next=p; } void delectLowerThanZero_node(PNode node){ if(node==NULL){ printf("NULL"); return; } PNode q,p; q=node; p=node->next; while(p!=NULL){ if(p->data<0){ q->next=p->next; free(p); p=q->next; } q=p; p=p->next; } } void printf_node(PNode node){ if(node==NULL) return; PNode p=node->next; while(p!=NULL){ printf("%d ",p->data); p=p->next; } printf(" "); }