• 検索結果がありません。

(2) 本問を選択

N/A
N/A
Protected

Academic year: 2021

シェア "(2) 本問を選択"

Copied!
1
0
0

読み込み中.... (全文を見る)

全文

(1)

アルゴリズム(2)

本問を選択(Select this problem){ する(Yes),しない(No) } 受験番号(No.)

次のように定義したラベルを持った二分木について,下の問題に答えよ。ただし,leftrightには子へのポ インタが入る。また,子がない場合には,NULL(= 0)が入れられているものとする。なお,解答には裏面も使用し て良い。(Answer the questions about the data structure of binary trees with labels defined below. A pointer to a child is assigned to the field left or right, and NULL (= 0) is assigned for indicating that no child exists. The reverse side can be used for the answers if needed.)

typedef struct btree btree;

struct btree { int label;

btree *left;

btree *right;

};

1:二分木のlabelの値の合計を返す関数を再帰呼び出しを使って定義せよ。(Q1: Define a function taking a binary tree and returning the total sum of the values of label. Use recursion in the definition.)

2: 1の関数を再帰呼び出しを使わず定義せよ。ただし,次のスタックを使え。(Q2: Define the same function as Q1 without recursion and with using the stack defined as follows:)

int stackp;

btree* stack[1000];

void initialize_stack(void) { stackp = 0; } void push(btree *x) { stack[stackp++] = x; } btree *pop(void) { return stack[--stackp]; } int empty_stack(void) { return stackp == 0; }

3:二分木のlabelの値を,深さ1()のノード,深さ2のノード,深さ3ノード,. . . の順で出力する関数 を定義せよ。(Q3: Define the function taking a binary tree and printing out the values of labelin order of the node in depth 1 (the root node), nodes in depth 2, nodes in depth 3, . . ..)

参照

関連したドキュメント

ぎり︑第三文の効力について疑問を唱えるものは見当たらないのは︑実質的には右のような理由によるものと思われ

その問いとは逆に、価格が 30%値下がりした場合、消費量を増やすと回答した人(図

下山にはいり、ABさんの名案でロープでつ ながれた子供たちには笑ってしまいました。つ

 講義後の時点において、性感染症に対する知識をもっと早く習得しておきたかったと思うか、その場

大村 その場合に、なぜ成り立たなくなったのか ということ、つまりあの図式でいうと基本的には S1 という 場

次のいずれかによって算定いたします。ただし,協定の対象となる期間または過去

現を教えても らい活用 したところ 、その子は すぐ動いた 。そういっ たことで非常 に役に立 っ た と い う 声 も いた だ い てい ま す 。 1 回の 派 遣 でも 十 分 だ っ た、 そ