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

(1) 本問を選択

N/A
N/A
Protected

Academic year: 2021

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

Copied!
1
0
0

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

全文

(1)

アルゴリズム(1)

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

以下は,値が文字(char型のデータ)のノードを持つリストを扱うC言語の関数群である.リストはinit_list() によって初期化され,insert_next()によってノードが追加されdelete_next()によって削除される.このプ ログラムに基づいて問に答えよ.(The following is a set of C functions dealing with a linear list whose values are characters (typechar). The list is initialized byinit_list(), and a node is inserted byinsert_next() and deleted by delete_next(). Assuming these functions, answer the questions below.)

#include <stdio.h>

#include <stdlib.h>

struct node { char key; struct node *next; };

struct node *head;

void init_list() {

head = (struct node *)malloc(sizeof(*head));

head->next = NULL;

}

struct node *insert_next(char v, struct node *t) {

struct node *x = (struct node *)malloc(sizeof(*x));

x->key = v; x->next = t->next; t->next = x;

return x;

}

void delete_next(struct node *t) {

if(t->next != NULL) {

struct node *x = t->next;

t->next = t->next->next;

free(x);

} }

1:以下は全てのノードを順に出力するプログラムである.空白([ (A) ]および[ (B) ]で示されている)

に入るべき文字を答えよ.(Q1: The folloing function prints out all the values in the list in order. Answer the parts of the program needed in the blanks indicated by [ (A) ]and [ (B) ].)

1(A1): (A) (B)

void print_all(void) {

struct node *x = [ (A) ];

while(x != [ (B) ]) { printf("%c",x->key);

x = x->next;

}

printf("\n");

}

2:次のプログラムの出力を答えよ.(Q2: Answer the output of the following program.) 2(A2):

int main(void) {

struct node *x;

init_list();

(void)insert_next(’A’,head);

x = insert_next(’B’,head);

(void)insert_next(’C’,x);

(void)insert_next(’D’,x);

print_all();

}

3:リストの中から,引数で指定された文字と同じ値を持つノードを全て削除する関数remove_char()を作成せ よ.remove_char()void型の関数で,char型の引数を一つ取るものとする.なお 解答には裏面を用いること.

(Q3: Write functionremove_char()that deletes all nodes whose value is equal to the character given through the argument. The function has onechar type argument, and the return type isvoid. Use the reverse side for the answer.)

参照

関連したドキュメント

い方が選ばれてよいはずである。 しかるに実際の会計慣行はそのようになっていない。 こ

(あるいは基本棚卸について), どの時期の受入 原価で代替するかが, これらの方法に表現され

下線部⒧について、1993 年に成⽴した EU は現在、危機的状況にあるとされて いる。2015 年以降に EU で問題となっていることを簡潔に述べなさい。

( 解答は裏面を使用しても構わない. You can use the reverse side of this paper for

Prove or disprove that L is a regular language.. ( 解答は裏面を使用しても構わない. You can use the reverse side of this paper for

Design the logic circuit with only NAND gates.. ( 解答は裏面を使用しても構わない。 You can use the reverse side of this paper for

Design the logic circuit with only NAND gates3. ( 解答は裏面を使用しても構わない。 You can use the reverse side of this paper for

奈良時代、肥後の初代国司・ ①