using System;
using System.Collections.Generic;
using static System.Console;
public class treeNode
{
public int childN;
public List<treeNode> branch;
public treeNode()
{
childN = 0;
}
}
public class program
{
static void Main()
{
int N;
N = int.Parse(ReadLine());
int[] ii = new int[N];
treeNode[] TN = new treeNode[N];
string input = ReadLine();
string[] inputArr = input.Split();
for(int i =0;i<N;i++)
{
ii[i] = int.Parse(inputArr[i]);
WriteLine(ii[i]);
if(ii[i] != -1)
{
TN[ii[i]].childN++; ///////// <<<<<------
TN[ii[i]].branch.Add(TN[i]);
}
}
}
}
언어 C#인데 저기 주석처리한곳에서 nullreference가 일어나
확인해보니까 TN[]이 null인거같아 근데 나 초보라 왜 그런건지 모르겠어
비슷하게 공간만든 ii[]는 null이 아니야 누가 좀 도와줘
저도 자세힌 모르겠지만 branch가 초기화 안되어 있지 ㅇ낳나용
쟤도 초기화 해놔야 하나요?? 필요할때 아니면 안넣으려한 애긴 한데
ㄴ 근데 밑에서 보시면 branch에 add하실려고 하는데 초기화도 안된 list에 add를 하니까 nullpointer 에러가 발생하는게 아닐까요
거기까진 코드가 실행안돼봐서 거긴 모르겠어요 그런데 TN[] 자체가 null이 되는데 그게 좀 문제에요