teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

ナイーブツリーに勝者情報も追加

2021/05/26 16:50

投稿

takezoux2
takezoux2

スコア6

title CHANGED
File without changes
body CHANGED
@@ -40,7 +40,7 @@
40
40
  ### 例2: 次の試合を保持
41
41
 
42
42
 
43
- ```scala3
43
+ ```Scala3
44
44
 
45
45
  case class Entry(
46
46
  id: string,
@@ -68,20 +68,24 @@
68
68
  ```python3
69
69
  from dataclasses import dataclass
70
70
 
71
+ WINNER = 1
72
+ LOSER = 2
73
+
71
74
  @dataclass
72
75
  class Node:
73
76
  id: str
74
77
  nextId: str
75
78
  name: str
79
+ winner: int
76
80
 
77
81
  [
78
- Node("E1","M1","田中太郎"),
82
+ Node("E1","M1","田中太郎", WINNER),
79
- Node("E2","M1","鈴木一郎"),
83
+ Node("E2","M1","鈴木一郎", LOSER),
80
- Node("M1","M3","第一試合"),
84
+ Node("M1","M3","第一試合", 0),
81
- Node("E3","M2","山田花子"),
85
+ Node("E3","M2","山田花子", 0),
82
- Node("E4","M2","佐藤櫻子"),
86
+ Node("E4","M2","佐藤櫻子", 0),
83
- Node("M2","M3","第二試合"),
87
+ Node("M2","M3","第二試合", 0),
84
- Node("M3",None,"決勝")
88
+ Node("M3",None,"決勝", 0)
85
89
  ]
86
90
 
87
91
  ```

1

コメントに対応。例を増やしてみた

2021/05/26 16:50

投稿

takezoux2
takezoux2

スコア6

title CHANGED
File without changes
body CHANGED
@@ -40,25 +40,78 @@
40
40
  ### 例2: 次の試合を保持
41
41
 
42
42
 
43
- ```typescript
43
+ ```scala3
44
44
 
45
- interface Entry{
45
+ case class Entry(
46
- id: string
46
+ id: string,
47
- entryName: string
47
+ entryName: string,
48
48
  matchId: string
49
- }
49
+ )
50
- interface Match{
50
+ case class Match(
51
- id: string
51
+ id: String
52
- matchName: string
52
+ matchName: String
53
- nextMatchId?: string
53
+ nextMatchId: Option[String]
54
- }
54
+ )
55
55
 
56
+ List[Entry | Match](
57
+ Entry("E1", "田中太郎", "M1"), Entry("E2", "鈴木一郎", "M1"),
58
+ Match("M1", "第一試合", Some("M3")),
59
+ Entry("E3", "山田花子", "M2") , Entry("E4", "佐藤櫻子", "M2"),
60
+ Match("M2", "第二試合", Some("M3")),
61
+ Match("M3", "決勝", None),
62
+ )
63
+
64
+ ```
65
+
66
+ ### 例3: コメント頂いたナイーブツリー
67
+
68
+ ```python3
69
+ from dataclasses import dataclass
70
+
71
+ @dataclass
72
+ class Node:
73
+ id: str
74
+ nextId: str
75
+ name: str
76
+
56
77
  [
78
+ Node("E1","M1","田中太郎"),
57
- {id: "E1", entryName: "田中太郎", matchId: "M1"} , {id: "E2", entryName: "鈴木一郎", matchId: "M1"},
79
+ Node("E2","M1","鈴木一郎"),
58
- {id: "M1", matchName: "第一試合", nextMatchId: "M3"},
80
+ Node("M1","M3","第一試合"),
81
+ Node("E3","M2","山田花子"),
59
- {id: "E3", entryName: "山田花子", matchId: "M2"} , {id: "E4", entryName: "佐藤櫻子", matchId: "M2"},
82
+ Node("E4","M2","佐藤櫻子"),
60
- {id: "M2", matchName: "第二試合"}, nextMatchId: "M3"},
83
+ Node("M2","M3","第二試合"),
61
- {id: "M3", matchName: "決勝"},
84
+ Node("M3",None,"決勝")
62
85
  ]
63
86
 
87
+ ```
88
+
89
+ ### 例4: コメント頂いたそのままシリアライズ(型付き言語の場合)
90
+
91
+ ```c#
92
+ public class Match {
93
+ public string Name {get; set;}
94
+ public Match[] Entries {get; set;}
95
+ }
96
+
97
+ new Match{
98
+ Name = "決勝",
99
+ Entries = new Match[]{
100
+ new Match {
101
+ Name = "第一試合",
102
+ Entries = new Match[]{
103
+ new Match {
104
+ Name = "田中太郎", Entries = new Match[0]
105
+ },
106
+ new Match {
107
+ Name = "鈴木一郎", Entries = new Match[0]
108
+ }
109
+ }
110
+ },
111
+ new Match {
112
+ // 略
113
+ }
114
+ }
115
+ }
116
+
64
117
  ```