91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 5KB
    文件類型: .cpp
    金幣: 1
    下載: 0 次
    發(fā)布日期: 2021-06-10
  • 語(yǔ)言: C/C++
  • 標(biāo)簽: 線性表??

資源簡(jiǎn)介

c語(yǔ)言實(shí)現(xiàn)線性表創(chuàng)建,插入,刪除及合并的源代碼。

資源截圖

代碼片段和文件信息


#include?
#include?
#include?
#include?

#define?OK?1
#define?ERROR?0
#define?OVERFLOW?0
#define?LIST_INIT_SIZE?100
#define?LISTINCREMENT?10

typedef?int?ElemType;
using?namespace?std;

typedef?struct
{
int?*elem;
int?length;
int?listsize;
}?SqList;


int?InitList_Sq?(SqList*??L)
{
(*L).elem=(int?*)malloc(LIST_INIT_SIZE*sizeof(int));
if(!(*L).elem)
exit(OVERFLOW);
(*L).length=0;
(*L).listsize=LIST_INIT_SIZE;
return?OK;
}

int?CreateList_Sq?(?SqList?L?)
{
int?i;
printf(“請(qǐng)輸入數(shù)據(jù):?\n“);
for(i=0;i scanf(“%d“&L.elem[i]);
return?OK;
}

int?InsertList_Sq?(?SqList?*L?int?i?ElemType?e?){
????ElemType?*newbase?*p?*q;
????if(i<1?||?i>L->length+1)
return?ERROR;
????if(L->length?>=?L->listsize)?
{
????????newbase?=?(ElemType?*)realloc(L->elem?(L->listsize+LISTINCREMENT)*sizeof(ElemType)?);
????????if(!newbase)
printf(“類存分配失敗“);
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;

}


int?ListDelete_Sq(?SqList?&L?int?i??int?&e?)
{
int?*p*q;
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;
cout<<“被刪除的結(jié)點(diǎn)為:“< return?OK;
}

void?PrintList_Sq?(?SqList?L?)
{
int?z=0;
????while(z? {
????????printf(“%3d“?L.elem[z]);
????????z++;
????}
printf(“\n“);
}

void?MergeList_Sq(SqList?La?SqList?Lb?SqList?*Lc)?{
????ElemType?*pa?*pb?*pc?*pa_last?*pb_last;
????pa?=?La.elem;
????pb?=?Lb.elem;
????Lc->listsize?=?Lc->length?=?La.length?+?Lb.length;
????Lc->elem?=?(ElemType*)?malloc?(Lc->listsize?*?sizeof(ElemType));
????pc?=?Lc->elem;
????if(!Lc->elem)?exit(OVERFLOW);
????pa_last?=?La.elem?+?La.length?-?1;
????pb_last?=?Lb.elem?+?Lb.length?-?1;
????while(?pa?<=?pa_last?&&?pb?<=?pb_last)?{
????????if(*pa?<=?*pb)?*pc++?=?*pa++;
????????else?*pc++?=?*pb++;
????}
????while(pa?<=?pa_last)?*pc++?=?*pa++;
????while(pb?<=?pb_last)?*pc++?=?*pb++;
}

void?INSERTION_SORT(SqList?*A)
{
????int?i?j?key;
????for(j?=?1;?j?!=?A->length;?j++)?{
????????key?=?A->elem[j];
????????i?=?j?-?1;
????????while(?i?>=?0?&&?A->elem[i]?>?key?)?{
????????????A->elem[i+1]?=?A->elem[i];
????????????--i;
????????}
??????

評(píng)論

共有 條評(píng)論