标签:
cunqu
charu
delete
find
length
merge(hebing);
ADT List{
D= { }
R= { }
Operation:
InitList(&L);
DestoryList(&L);
ListLength(L);
ListInsert(&L,i,e);
ListDelete(&L,i,&e);
}ADT List
#define LIST_INT_SIZE 100
#define LISTINCREMENT 10
typedef struct SqList
{
ElemType *elem;
int length;
int listsize;
} Sqlist;
Status InitList_Sq(Sqlist &L)
{
L.elem=(ElemType*)malloc(LIST_INIT_SIZE*sizeof(ElemType));
if(!L.elem) exit(OVERFLOW);
L.length=0;
L.listsize=LIST_INIT_SIZE;
return OK;
}
2 4 7 9 5 6
Status ListInsert_Sq(Sqlist &L,int i,ElemType e)
{
if(i<1||i>L.length+1)
return ERROR;
if(L.length>=L.listsize)
{
newbase=(ElemType*)realloc(L.elem,(L.listsize+LISTINSCREMENT)*sizeof(ElemType));
if(!newbase) exit(OVERFLOW);
L.elem=newbase;
L.listsize+=LISTINCREMENT;
}
q=&(L.elem[i-1]);
for(p=&(L.elem[L.length-1]);p>=q;--p)
*(p+1)=*p;
*q=e;
++L.length;
return OK;
}//T(n)=n/2; O(n)
Status ListDelete_Sq(SqList &L,int i,ElemType &e)
{
if(i<1||i>L.length) return ERROR;
p=&(L.elem[i-1]);
e=*p;
q=L.elem+L.length-1;
for(++p;p<=q;++p)
*(p-1)=*p;
--L.length;
Return OK;
}
LocateElem_Sq(Sqlist &L,ElemType &x)
{
for(i=0;i<=L.length-1;i++)
{
if(L.elem[i]==x)
return (i+1);
if(i>L.length-1)
return (0);
}
}
------------------
typedef struct LNode
{
ElemType data;
struct Lnode *next;
}Lnode,*LinkList;
L=(LinkList)malloc(sizeof(LNode));
L->next=NULL;
LNode *head=L;
p=(LinkList)malloc(sizeof(LNode));
标签:
原文地址:http://www.cnblogs.com/htmlphp/p/4884860.html