6 2 兩個有序鍊錶序列的合併 (14 分)

2021-09-07 03:19:24 字數 1086 閱讀 9461

本題要求實現乙個函式,將兩個鍊錶表示的遞增整數序列合併為乙個非遞減的整數序列。

函式介面定義:

list merge( list l1, list l2 );

其中list結構定義如下:

typedef struct node ptrtonode;

struct node ;

typedef ptrtonode list; / 定義單鏈表型別 */

l1和l2是給定的帶頭結點的單鏈表,其結點儲存的資料是遞增有序的;函式merge要將l1和l2合併為乙個非遞減的整數序列。應直接使用原序列中的結點,返回歸併後的帶頭結點的煉表頭指標。

裁判測試程式樣例:

#include

#include

typedef

int elementtype;

typedef

struct node *ptrtonode;

struct node

;typedef ptrtonode list;

list read()

;/* 細節在此不表 */

void

print

( list l )

;/* 細節在此不表;空煉表將輸出null */

list merge

( list l1, list l2 )

;int

main()

/* 你的**將被嵌在這裡 */

輸入樣例:

31 3 5

52 4 6 8 10

輸出樣例:

6 2 兩個有序鍊錶序列的合併 15分

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

合併兩個有序鍊錶序列

本題要求實現乙個函式,將兩個鍊錶表示的遞增整數序列合併為乙個非遞減的整數序列。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...