1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
| linklist *createlist() { char ch; int x; linklist *s,*head; head=NULL; ch=getchar(); while(ch!='*') { scanf("%d",&x); s=(linklist*)malloc(sizeof(linklist)); s->data=x; s->next=head; head=s; ch=getchar(); } return head; }
linklist *creatlist() { char ch; int x; linklist *head,*r,*s; head=(linklist*)malloc(sizeof(linklist)); r=head; ch=getchar(); while(ch!='*') { scanf("%d",&x); s=(linklist*)malloc(sizeof(linklist)); s->data=x; r->next=s; r=s; ch=getchar(); } r->next=NULL; return (head); }
linklist *lookpoint(linklist *head,int i) { int j=0; linklist *p; p=head; while(p->next!=NULL&&j<i) { p=p->next; j++; } if(i==j) return p; else return NULL; }
linklist *lookkey(linklist *head,int key) { linklist *p; p=head->next; while(p!=NULL) { if(p->data!=key) p=p->next; else break; } return p; } void insert(linklist *p,int x) { linklist *s; s=(linklist *)malloc(sizeof(linklist)); s->data=x; s->next=p->next; p->next=s; }
void INSERT(linklist *p,int i,int x) { linklist *L; int j; j=i-1; L=lookpoint(p,j); insert(L,x); }
void beforeinser(linklist *p,int x) { linklist *s; s=(linklist *)malloc(sizeof(linklist)); s->data=p->data; s->next=p->next; p->data=x; p->next=s; } void deleter(linklist *p) { linklist *r; r=p->next; p->next=r->next; free(r);; } void print(linklist *head) { linklist *p; p=head->next; while(p!=NULL) { printf("%d ",p->data); p=p->next; } printf("\n"); }
|