工程实践:求两个有序集合的并集依然有序之链表法


#include
#include
#define TRUE 1
#define FALSE 0
#define ERROR 0
#define OVERFLOW -1
#define OK 1;
typedef int Status; /**Status是函数类型,其值是函数结果状态代码,如OK等**/
typedef int ElemType; 
typedef int Status; /**Status是函数类型,其值是函数结果状态代码,如OK等**/
typedef int ElemType; 


struct LNode               /* 结点定义 */     
{
	ElemType data;
	struct LNode *next;
};
typedef struct LNode *LinkList; /* 表的头指针类型 */
LinkList La,Lb,Lc;



Status InitList(LinkList *L)
{
	*L=(LinkList)malloc(sizeof(struct LNode));
	
	if(!*L) exit(OVERFLOW);
	
	(*L)->next=NULL;
	return OK;
}


int ListLength(LinkList L)
{
	int i=0;
	LinkList p=L->next;
	
	
	while(p)
	{
		p=p->next;
		i++;
	}
	return i;
}


Status GetElem(LinkList L,int i,ElemType *e)
{ 
	int j=1; /* j为计数器 */
	
	LinkList p=L->next; /* p指向第一个结点 */
	
	while(p&&jnext;
		j++;
	} 	
	if(!p||j>i)   /* 第i个元

你可能感兴趣的:(算法,数据结构)