Open hayato0718 opened 4 years ago
せいかい
ア class Calc
ウ def initialize
サ @x = 0
エ end
イ def get
ス @x = -@x
セ @x = @x + 1
ス @x = -@x
オ return @x
エ end
エ end
まちがい
ア class Calc
エ def initialize
タ @val1.push(x)
ソ @val1 = @val1 + x
オ end
ウ def get
ノ return 0.5 * (@val1 + @val2)
オ end
オ end
せいかい
ア class Calc
エ def initialize
シ @val1 = 0
ツ @val2 = 0
オ end
イ def put(x)
ソ @val1 = @val1 + x
ト @val2 = @val2 + 1
ナ return x
オ end
ウ def get
ネ return @val1 / @val2.to_f
オ end
オ end
Cell = Struct.new(:data, :next)
p = Cell.new(1, Cell.new(2, Cell.new(3, nil)))
def listsum(p)
sum = 0
while p != nil do
sum += p.data
p = p.next
end
return sum
end
p listsum(p)
def listcat(p)
linked_string = ''
while p != nil do
linked_string += p.data.to_s
p = p.next
end
return linked_string
end
p listcat(p)
def listcatrev(p)
datas = []
while p != nil do
datas.push(p.data.to_s)
p = p.next
end
return datas.reverse.join
end
p listcatrev(p)
def printmany(p)
count = 0
while p != nil do
count += 1
puts(p.data.to_s * count)
p = p.next
end
end
printmany(p)
def listoddsum(p)
sum = 0
while p != nil do
sum += p.data
break if p.next.nil?
p = p.next.next
end
return sum
end
p = Cell.new(1, Cell.new(2, Cell.new(3, nil)))
p listoddsum(p)
p = Cell.new(1, Cell.new(2, nil))
p listoddsum(p)
p = Cell.new(1, Cell.new(2, Cell.new(3, nil)))
def ltoa(p)
cells = []
while p != nil do
cells.push(p)
p = p.next
end
return cells
end
pp ltoa(p)
# 例題
Cell = Struct.new(:data, :next)
def nlist1(n)
p = nil
n.times do |i|
p = Cell.new(i, p)
end
return p
end
def nlist1_r(n)
if n <= 0
return nil
else
return Cell.new(n, nlist1_r(n - 1))
end
end
p nlist1 3
p nlist1_r 3
# 演習2a
def nlist_asc(n)
p = nil
n.downto(1) do |i|
p = Cell.new(i, p)
end
return p
end
p nlist_asc 3
# 演習2b
def list_array(a)
p = nil
a.reverse_each do |v|
p = Cell.new(v, p)
end
return p
end
p list_array(['a', 'b', 'c'])
p = Cell.new(1, Cell.new(2, Cell.new(3, nil)))
#Cell.new(1, Cell.new(3, nil))
# 演習2c
#def list_delete_even(p)
# lists = nil
# while p != nil do
# list = Cell.new(p.data, nil))
# if p.next.nil?
# lists.push = list
# end
# list.next =
# p = p.next.next
# sum += p.data
# p = p.next
# end
# return lists
#end
活動内容報告 #10
学籍番号:1920031
氏名:山川竜太郎
ペア学籍番号・氏名(または「個人作業」):
提出日付:2019/12/23
[作成したプログラム]
Cell = Struct.new(:data, :next)
p = Cell.new(1, Cell.new(2, Cell.new(3, nil)))
def listsum(p)
sum = 0
while p != nil do
sum += p.data
p = p.next
end
return sum
end
p listsum(p)
def listcat(p)
linked_string = ''
while p != nil do
linked_string += p.data.to_s
p = p.next
end
return linked_string
end
p listcat(p)
def listcatrev(p)
datas = []
while p != nil do
datas.push(p.data.to_s)
p = p.next
end
return datas.reverse.join
end
p listcatrev(p)
def printmany(p)
count = 0
while p != nil do
count += 1
puts(p.data.to_s * count)
p = p.next
end
end
printmany(p)
def listoddsum(p)
sum = 0
while p != nil do
sum += p.data
break if p.next.nil?
p = p.next.next
end
return sum
end
p = Cell.new(1, Cell.new(2, Cell.new(3, nil)))
p listoddsum(p)
p = Cell.new(1, Cell.new(2, nil))
p listoddsum(p)
p = Cell.new(1, Cell.new(2, Cell.new(3, nil)))
def ltoa(p)
cells = []
while p != nil do
cells.push(p)
p = p.next
end
return cells
end
pp ltoa(p)
# 例題
Cell = Struct.new(:data, :next)
def nlist1(n)
p = nil
n.times do |i|
p = Cell.new(i, p)
end
return p
end
def nlist1_r(n)
if n <= 0
return nil
else
return Cell.new(n, nlist1_r(n - 1))
end
end
p nlist1 3
p nlist1_r 3
# 演習2a
def nlist_asc(n)
p = nil
n.downto(1) do |i|
p = Cell.new(i, p)
end
return p
end
p nlist_asc 3
# 演習2b
def list_array(a)
p = nil
a.reverse_each do |v|
p = Cell.new(v, p)
end
return p
end
p list_array(['a', 'b', 'c'])
[簡単な説明]
演習1と2のbまで終わった
[アンケート]
Q1. 動的データ構造とはどのようなものか理解しましたか。
むずかしいです
Q2. 連結リストの操作ができるようになりましたか。
むずかしいです
Q3. リフレクション(今回の課題で分かったこと)・感想・要望をどうぞ。
むずかしいです
‘‘‘ 活動内容報告 #10 学籍番号:1920003 氏名:伊東 隼人 ペア学籍番号・氏名(山川隆太羅王):1920031 提出日付:12/23
[作成したプログラム]
活動内容報告 #10 学籍番号: 氏名: ペア学籍番号・氏名(または「個人作業」): 提出日付:
[作成したプログラム]
Cell = Struct.new(:data, :next)
def listlen(p) len = 0 while p != nil do len = len + 1; p = p.next end return len end
def listlen_r(p) # 再帰版 if p == nil return 0 else return listlen_r(p.next) + 1 end end
def printlist(p) while p != nil do puts(p.data); p = p.next end end
def printlist_r(p) # 再帰版 if p != nil then puts(p.data) printlist_r(p.next) end end
def revprintlist_r(p) if p != nil then revprintlist_r(p.next) puts(p.data) end end
def nlist1(n) p = nil n.times do |i| p = Cell.new(i, p) end return p end
def nlist1_r(n) # 再帰版 if n <= 0 return nil else return Cell.new(n, nlist1_r(n-1)) end end
def listsum(p) sum = 0 while P != nil do sum += P.data p = p.next end return sum end
def listat(p) linked_string = '' while p != nil do linked_string += p.data.to_s P = p.next end return linked_string end
def listcatrev(p) p.reverse linked_string = [] while p != nil do p.linked_string.class linked_string.push(p.data.to_s) p = p.next end
[簡単な説明]
[アンケート] Q1. 動的データ構造とはどのようなものか理解しましたか。 難しい。ほぼ理解できていないです。 Q2. 連結リストの操作ができるようになりましたか。 超簡単なものだけできました。 Q3. リフレクション(今回の課題で分かったこと)・感想・要望をどうぞ。 簡単な連結はマスターしたい。 [簡単な説明]
[アンケート] Q1. 動的データ構造とはどのようなものか理解しましたか。
Q2. 連結リストの操作ができるようになりましたか。
Q3. リフレクション(今回の課題で分かったこと)・感想・要望をどうぞ。
まちがい