PTA6 3 求鏈式表的表長(包含read())

2021-10-01 15:14:51 字數 1010 閱讀 2705

本題要求實現乙個函式,求鏈式表的表長

int

length

( list l )

;

其中list結構定義如下:

typedef

struct lnode *ptrtolnode;

struct lnode

;typedef ptrtolnode list;

l是給定單鏈表,函式length要返回鏈式表的長度。

#include

#include

typedef

int elementtype;

typedef

struct lnode *ptrtolnode;

struct lnode

;typedef ptrtolnode list;

list read()

;/* 細節在此不表 */

intlength

( list l )

;int

main()

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

1 3 4 5 2 -1

ac**(包含測試程式樣例省略的read()):

int

length

(list l)

return i;

}//read()函式

list read()

list l=

(list)

malloc

(sizeof

(struct lnode));

list p=l;

l->data=num;

l->next=

null

;scanf

("%d"

,&num)

;while

(num!=-1

)return l;

}

6 3 求鏈式表的表長

本題要求實現乙個函式,求鏈式表的表長。int length list l 其中list結構定義如下 typedef struct lnode ptrtolnode struct lnode typedef ptrtolnode list l是給定單鏈表,函式length要返回鏈式表的長度。inclu...

6 3 求鏈式表的表長

6 3 求鏈式表的表長 10 分 本題要求實現乙個函式,求鏈式表的表長。int length list l 其中list結構定義如下 typedef struct lnode ptrtolnode struct lnode typedef ptrtolnode list l是給定單鏈表,函式leng...

6 3 求鏈式表的表長 (10 分)

本題要求實現乙個函式,求鏈式表的表長。函式介面定義 int length list l 其中list結構定義如下 typedef struct lnode ptrtolnode struct lnode typedef ptrtolnode list l是給定單鏈表,函式length要返回鏈式表的長...