연결된 목록 데이터 형식의 작은 샘플을 구현하려고했습니다. 나는 값을 가지고있는 struct Node를 만들었고, 연결된리스트 형식의 모든 노드를 추적하는 struct List를 만들었습니다. 마지막으로 두 구조체의 일반적인 데이터 유형 인 클래스입니다. 항목 -> 링크 [내가 ++] = 새로운 노드 (입력)세그먼트 오류 포인터
코드 :
struct Node
{
int val;
Node();
Node(int x);
};
struct List
{
Node *link[20];
List();
};
class pol
{
public:
void read_txt(ifstream &file);
private:
List *item;
};
void pol::read_txt(ifstream &file)
{
int input, i;
i = 0;
file >> input;
cout << "Value read from the file: " << input << endl;
while(input != 0)
{
item.link[i++] = new Node(input);
file >> input;
cout << "Value read from the file: " << input << endl;
}
}
나는이 프로그램을 실행했을 때 나는이 단계에 도달로
, 나는 항상 즉시 세그먼트 오류 오류가 발생했습니다
내가하려는 것은 파일을 읽음으로써 얻을 수있는 "입력"값을 가진 새로운 노드를 생성하는 것입니다. 다음으로, 모든 노드가 연결된 링크드리스트를 만들고 싶습니다.
이'item.link'는'item'이'List *':'item-> link'이므로 컴파일해서는 안됩니다. – hmjd