Skip to content
c
#define TRUE  1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW   -2

typedef int Status;

typedef int ElemType;
typedef struct LNode {
   ElemType data;
   LNode *next;
} LNode, *LList;

void Insert(LList *L, ElemType e) {  
  LList r, s, t;
  if (!(t=(LList)malloc(sizeof(LNode)))) exit(OVERFLOW);
  t->data=e;
  if (!*L) {
    t->next = NULL;  
    *L=t; 
  } else if (e < (*L)->data) {  
    t->next = *L;
    *L = t;
  } else {   
    s = *L;
    while (s && s->data<e) {  
      r = s;
      s = s->next;
    } 
    t->next = s;  
    r->next = t;  
  }
}

持之苟有恒,久久自芬芳