#include<stdio.h>
#include<stdlib.h>
typedef struct Lnode
{int data;struct Lnode *next;}ListNode;typedef ListNode *LinkList;LinkList Create(){LinkList p,q,head;int x;head=malloc(sizeof(ListNode));p=head;printf("\n输入数据 -1 作为结束标志:\n");scanf("%d",&x);while(x!=-1){q=malloc(sizeof(ListNode));q->data=x;p->next=q;p=q;scanf("%d",&x);}p->next=NULL;return (head);}void Print(LinkList head){LinkList p,q;p=head->next;while(p!=NULL){printf("%d ",p->data);p=p->next;}printf("\n");}void DelList(LinkList head,int i){LinkList pre,p;int k;pre=head;k=0;while (pre->next!=NULL&&k<i-1){pre=pre->next;k=k+1;}if (!(pre->next)&&k<=i-1)printf("Error");else{p=pre->next;pre->next=pre->next->next;free(p);}}
main(){LinkList h;printf("\n创建的列表:");h=Create();printf("\n单链表中的数据为:");Print(h);}
#include<stdlib.h>
typedef struct Lnode
{int data;struct Lnode *next;}ListNode;typedef ListNode *LinkList;LinkList Create(){LinkList p,q,head;int x;head=malloc(sizeof(ListNode));p=head;printf("\n输入数据 -1 作为结束标志:\n");scanf("%d",&x);while(x!=-1){q=malloc(sizeof(ListNode));q->data=x;p->next=q;p=q;scanf("%d",&x);}p->next=NULL;return (head);}void Print(LinkList head){LinkList p,q;p=head->next;while(p!=NULL){printf("%d ",p->data);p=p->next;}printf("\n");}void DelList(LinkList head,int i){LinkList pre,p;int k;pre=head;k=0;while (pre->next!=NULL&&k<i-1){pre=pre->next;k=k+1;}if (!(pre->next)&&k<=i-1)printf("Error");else{p=pre->next;pre->next=pre->next->next;free(p);}}
main(){LinkList h;printf("\n创建的列表:");h=Create();printf("\n单链表中的数据为:");Print(h);}
