02b1] 情報隠蔽されたバッファmaxbuf

次のような内容のヘッダファイルmaxbuf.hがある。

struct maxbuf;
typedef struct maxbuf *maxbufp;
maxbufp maxbuf_new(void);
void maxbuf_put(maxbufp r, int x);
int maxbuf_get(maxbufp r);

このAPIは、まずmaxbuf_newで作成したバッファに対して1回以上 maxbuf_putで整数を投入した後、maxbuf_getで値を取得すると、これま でに投入した値の最大値が返される(getより前に必ず1回は_putが呼ば れるものとしてよい)。このAPIの実装を作成せよ。下請け関数は使用し ないこととする。

記号列 

コード 

選択肢

ア #include <stdbool.h>
イ #include <stdlib.h>
ウ #include "maxbuf.h"
エ #include "oddsum.h"
オ struct maxbuf { int flag, val; };
カ struct oddsum { int flag, val; };
キ maxbufp maxbuf_new(void) {
ク oddsump oddsum_new(void) {
ケ void maxbuf_put(maxbufp r, int x) {
コ void oddsum_put(oddsump r, int x) {
サ int maxbuf_get(maxbufp r) {
シ int oddsum_get(oddsump r) {
ス }
セ maxbufp r = (maxbufp)malloc(sizeof(struct maxbuf));
ソ oddsump r = (oddsump)malloc(sizeof(struct oddsum));
タ if(r->flag || r->val < x) {
チ if(r->flag) {
ツ } else if(r->val < x) {
テ r->flag = !(r->flag);
ト r->flag = false;
ナ r->flag = true;
ニ r->val = 0;
ヌ r->val = r->val + x;
ネ r->val = x;
ノ return r->val;
ハ return r;

選択肢の行をドラグして上のコード領域に配置してください。 コード領域の行はドラグにより位置が変更できます。 削除したい場合は選択肢の領域に戻してください。