如何用c語言編合併兩個順序線性表的程式

時間 2021-06-30 23:18:52

1樓:匿名使用者

1、 一開始的思路:把a、b都丟進c裡,然後對c排序。人們一開始想到的總是最懶的辦法,往往是最沒效率的。

改進:由於a、b是排好序的,先把a丟進c裡,再拿b元素一個個往裡查詢插入。這麼做要頻繁移動元素,如果線性表不是連結串列的話,開銷很大。

再改進:從a、b中各拿一個元素出來,比較後把小的放進c裡,再從剛才拿出元素的那個表裡再拿個元素出來,再比較,把小的放進c裡,重複這樣的操作,直到a、b其中一箇中的元素拿完為止,再把還有剩的元素全丟進c裡。

2、例程:

#include

/*順序表儲存空間長度的最小值*/

#define listminsize 10

/*順序表儲存結構型別定義*/

typedef struct

seqlist;

/*順序表初始化*/

void listinitialize(seqlist *pl, int size)

/*按給定的下標取順序表元素值*/

bool listelem(seqlist l, int index, listdt *pelem)

/*求順序表長度*/

int listlen(seqlist l)

/*在順序表中指定序號位置插入元素*/

bool listinsert(seqlist *pl, int pos, listdt d)

return***;

}/*把順序表中指定序號的元素刪除*/

bool listdel(seqlist *pl, int pos)

return***;

}/*在順序表中查詢元素*/

int listloc(seqlist l, listdt d,bool (*equal)(listdt,listdt))

/*取前導元素序號位置*/

bool listprior(seqlist l, int pos, int *ppriorpos)

{bool***=true;

if(pos>0&& pos=0&& pos

2樓:匿名使用者

void combl(sqlist *pa, sqlist *pb)/*合併函式*/

pa->a = pt; /*交換陣列*/

}我沒有除錯過,你自己除錯一下吧!大概思路是這樣的!

資料結構c語言版,順序線性表的合併程式。最好有註釋

3樓:防禦

//希望我的回答對你的學習有幫助

#include

/*順序表儲存空間長度的最小值*/

#define listminsize 10

/*順序表儲存結構型別定義*/

typedef struct

seqlist;

/*順序表初始化*/

void listinitialize(seqlist *pl, int size)

/*按給定的下標取順序表元素值*/

bool listelem(seqlist l, int index, listdt *pelem)

/*求順序表長度*/

int listlen(seqlist l)

/*在順序表中指定序號位置插入元素*/

bool listinsert(seqlist *pl, int pos, listdt d)

return***;

}/*把順序表中指定序號的元素刪除*/

bool listdel(seqlist *pl, int pos)

return***;

}/*在順序表中查詢元素*/

int listloc(seqlist l, listdt d,bool (*equal)(listdt,listdt))

/*取前導元素序號位置*/

bool listprior(seqlist l, int pos, int *ppriorpos)

{bool***=true;

if(pos>0&& pos=0&& pos

4樓:匿名使用者

#include

#include

#include

typedef int elemtype;

const int maxsize = 100;

typedef struct sqlist *sqlist;

sqlist getemptylist()int addelem(sqlist list, elemtype x)

}list->data[list->size] = x;

++list->size;

return 1;

}void showlist(sqlist list)printf("\n");

if(i % 20) printf("\n");

}sqlist mergelist(sqlist la, sqlist lb)

int main()

lc = mergelist(la,lb);

printf("la:\n");

showlist(la);

printf("lb:\n");

showlist(lb);

printf("lc:\n");

showlist(lc);

return 0;}

5樓:風若遠去何人留

#include

typedef struct

t;void join(t a, t b, t *c)for(;ia[c->n++] = a.a[i++];

for(;ja[c->n++] = b.a[j++];

}int main()

};t b = };

t c;

int i;

join(a, b, &c);

for(i = 0; i < c.n; i ++)printf("%d ", c.a[i]);

printf("\n");}

sai怎麼合併兩個圖層,如何用sai把兩個檔案的圖片合併成一個檔案兩個圖層或別的

橘子汽水有點 我其實是來找答案的然後自己瞎搞發現這樣可以,如果不是你想要的操作就無視了?我試了一下,把要合併的其中一個圖層裡的圖用選擇工具 不知道套索工具行不行 選中,ctrl c複製,然後到另一圖層新建個空白圖層ctrl v貼上,會出現一個新圖層,同樣的方法選中另一圖層的內容複製,貼上到上面新建的...

易語言如何把兩個原始碼合併,易語言如何把兩個原始碼合併

直接考入是行不通的,具體原因,就是有重複,怎麼做的話,你先排除有名字相同的控制元件,變數,就是讓你改名字 然後把建立完畢事件中的 複製到想要程式中 當然也是貼上到建立完畢事件中啦 再把其他的拷貝進去。哦!對了,你先把控制元件弄好了再複製 哦 看得懂不?哦!仔細看了一下你的問題補充,如果要引用外部程式...

C語言兩個連線問題,C語言兩個檔案連線問題

連線?誰與誰呀?include 檔案2.h 你的第一個檔名是什麼?比如你的第一個檔名是 score.c 你需要在第二個檔案的開頭加上一個 include score.c 加以引入第一個檔案,另外這兩個檔案還需要在同一個工作區中。c語言怎樣把多個檔案連起來!將一個函式寫在一個檔案裡,然後再在另一個檔案...