私は以下を実装しようとしています。リスト - 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
更新された質問 – Thatdude1
破壊的なアイコンとは何ですか?戻り値の型を変更できますか? – sehe