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(); /* 細節在此不表 */
int length( list l );
int main()
/* 你的**將被嵌在這裡 */
1 3 4 5 2 -1
int
length
( list l )
return count;
}
#include
#include
typedef
int elementtype;
typedef
struct lnode *ptrtolnode;
struct lnode
;typedef ptrtolnode list;
list read
(void);
//讀入資料並建立鍊錶
void
delete
(list l)
;//釋放記憶體
intlength
( list l )
;//計算長度
intmain
(void
)/* 你的**將被嵌在這裡 */
list read
(void
)
list record=head;
for(
int i=0;
;i++
)else
p->data=num;
p->next=
null
; record->next=p;
//把新結點接上
record=p;
//record後移指向新結點}}
return head;
}void
delete
(list l)
}int
length
( list l )
return count;
}
6 3 求鏈式表的表長 (10 分)
本題要求實現乙個函式,求鏈式表的表長。函式介面定義 int length list l 其中list結構定義如下 typedef struct lnode ptrtolnode struct lnode typedef ptrtolnode list l是給定單鏈表,函式length要返回鏈式表的長...
6 3 求鏈式表的表長 10分
本題要求實現乙個函式,求鏈式表的表長。函式介面定義 int length list l 其中list結構定義如下 typedef struct lnode ptrtolnode struct lnode typedef ptrtolnode list l是給定單鏈表,函式length要返回鏈式表的長...
6 3 求鏈式表的表長 10分
函式介面定義 int length list l 其中list結構定義如下 typedef struct lnode ptrtolnode struct lnode typedef ptrtolnode list l是給定單鏈表,函式length要返回鏈式表的長度。裁判測試程式樣例 include ...