#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct LNode { void *data; struct LNode *next; } LNode,*LinkList; #define TRUE 1 #define FLASE 0 #define OK 1 #define ERROR 0 #define INFEASIBLE -1 #define OVERFLOW -2 typedef int Status; typedef int ElemType ; Status GetElem_L(LinkList L,int i,ElemType &e){ LinkList p;int j; p=L->next;j=1; while(p &&j<i){ p=p->next;++j; } if(!p||j>i)return OK; }//GetElem_L 算法2.8 Status ListInsert_L(LinkList &L,int i, ElemType e){ LNode p; int j; 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; }//ListInsert_L 算法2.9 Status ListDestroy_L(LinkList &L,int i,ElemType &e){ LinkList p,q;int j; 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; }//ListDestroy_L 算法2.10 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; } }//算法2.11 CreateList_L void MergetList_L(LinkList &La,LinkList &Lb,LinkList &Lc){ LinkList pa,pb,pc; pa=La->next;pb=Lb->next; Lc=pc=La; while(pa&&pb){ if(pa->data<=pb->data){ pc->next=pa;pc=pa;pa=pa->next; } else{pc->next=pb;pc=pb;pb=pb->next;} } pc->next=pa?pa:pb; free(Lb); }//void MergetList_L 算法2.12 int main(int argc, char **argv) { return OK; }
存在bug 3個 看誰能找出來