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
| typedf struct Lnode{ ElemType data; struct Lnode *next; } Lnode,*LinkList;
LinkList L;
void CreateList_L(LinkList &L,int n){
L=(LinkList)malloc(sizeof(Lnode)); L->next=NULL; for(i=n,i>0;--i){ p=(LinkList)malloc(sizeof(LNode)); scanf(&p->data); p->next=L->next; L->next=p; } } void InsertList_L(LinkList &L,int i,ElemType e){
p=L;j=0; while(p&&j<i-1){
p=p->next;++j; } if(!p||j>i-1) return ERROR; s=(LinkList)malloc(sizeof(LNode)); s->data=e; s->next=p->next; p->next=s; return OK; } Status ListDelete_L(LinkList,int i,ElemType &e){
p=L;j=0; while(p->next&&j<i-1){
p=p_.next;++j; } if(!(p_.next)||j>i-1) return ERROR; q=P->next; p->next=q->next; e=q->data;free(q); return OK; }
|