所以我試圖執行以下;列表 - C(作業)
// Destructive Abstract data type ilist
struct ilist_ADT;
typedef struct ilist_ADT *ilist;
// prototype for secret implementation
// do not rely on ilist being a pointer
ilist iempty();
// returns an empty ilist
int iempty_huh(ilist il);
// returns 1 (true) if il is empty
// returns 0 (false) if il is not empty
int ifirst(ilist il);
// returns the first element in il
// il must not be empty
ilist icons_destroy(int in, ilist il);
// returns an ilist with in added as the first element of il
// references to il cease to be valid ilists
// the result must eventually be consumed by one of:
// icons_destroy, irest_destroy, idelete
ilist irest_destroy(ilist il);
// modifies il to remove the first element, and returns the modified ilist
// frees the memory associated with the first element
// references to il cease to be valid ilists
// the result (if non-empty) must eventually be consumed by one of:
// icons_destroy, irest_destroy, idelete
ilist icopy(ilist il);
// returns a new copy of il that continues to be a valid
// ilist with the same elements even when il is destroyed
// the result must eventually be consumed by one of:
// icons_destroy, irest_destroy, idelete
int ilength(ilist il);
// computes the number of elements in il
void idelete(ilist il);
// frees the storage for ilist
// all further references to il become invalid
// NOTE: every ilist created by icons_destroy or
// irest_destroy or icopy must eventually be destroyed
// by being consumed by icons_destroy or
// irest_destroy or idelete
我專注於圖標第一,和我有一個非破壞性的圖標,如:
ilist icons(int in, ilist il) {
ilist r = malloc(sizeof(struct ilist_ADT));
r->first = in;
r->rest = il;
r->length = 1 + ilength(il);
return r;
}
究竟是如何將我讓這個以適應執行?換句話說,我該如何破壞它?
我在這裏找不到問題。你可以問一個簡單的問題,在這裏提出整個問題,而不是在其他地方提到頁面? – ugoren 2012-02-11 20:07:00
更新的問題 – Thatdude1 2012-02-12 01:30:42
什麼是破壞性圖標?我們可以改變返回類型嗎? – sehe 2012-02-12 01:36:11