兩個有序鍊錶序列的合併

2021-08-28 14:51:54 字數 1084 閱讀 6021

已知兩個非降序鍊錶序列s1與s2,設計函式構造出s1與s2合併後的新的非降序鍊錶s3。

輸入分兩行,分別在每行給出由若干個正整數構成的非降序序列,用−1表示序列的結尾(−1不屬於這個序列)。數字用空格間隔。

在一行中輸出合併後新的非降序鍊錶,數字間用空格分開,結尾不能有多餘空格;若新鍊錶為空,輸出null

1 3 5 -1

2 4 6 8 10 -1

1 2 3 4 5 6 8 10
#include

#include

#include

#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

lnode,

*linklist;

status listcreate_cl

(linklist &cl)

;void

listprint_cl

(linklist &l)

else

printf

(" %d"

, t->data)

; t = t->next;}}

intmain()

else

if(pa->data>pb->data)}if

(pa)

else

listprint_cl

(c3)

;return0;

}status listcreate_cl

(linklist &cl)

else

}return ok;

}

合併兩個有序鍊錶序列

本題要求實現乙個函式,將兩個鍊錶表示的遞增整數序列合併為乙個非遞減的整數序列。list merge list l1,list l2 其中list結構定義如下 typedef struct node ptrtonode struct node typedef ptrtonode list 定義單鏈表型...

兩個有序鍊錶序列的合併

習題2.5 兩個有序鍊錶序列的合併 15分 本題要求實現乙個函式,將兩個鍊錶表示的遞增整數序列合併為乙個非遞減的整數序列。list merge list l1,list l2 其中list結構定義如下 typedef struct node ptrtonode struct node typedef...

兩個有序鍊錶序列的合併

已知兩個非降序鍊錶序列s1與s2,設計函式構造出s1與s2的並集新非降序鍊錶s3。輸入分兩行,分別在每行給出由若干個正整數構成的非降序序列,用 表示序列的結尾 不屬於這個序列 數字用空格間隔。在一行中輸出合併後新的非降序鍊錶,數字間用空格分開,結尾不能有多餘空格 若新鍊錶為空,輸出null。1 3 ...