sách gpt4 ai đã đi

Lỗi phân đoạn trong null - Kiểm tra NULL?

In lại 作者:行者123 更新时间:2023-12-03 08:23:33 31 4
mua khóa gpt4 Nike

我在尝试检查某些元素是否为 VÔ GIÁ TRỊ 时遇到段错误或不。任何人都可以帮忙吗?

    void addEdge(int i, int j) 
{
if (i >= 0 && j > 0)
{
Node* whereto;
whereto = linkedAdjacencyList[i];
if(whereto != NULL)
{
while(whereto->adj != NULL)
{whereto = whereto->adj;}
whereto->adj = linkedAdjacencyList[j];
}
else{linkedAdjacencyList[i]->adj = linkedAdjacencyList[j];}
whereto = linkedAdjacencyList[j];
if(whereto != NULL)
{
while(whereto->adj != NULL)
{whereto = whereto->adj;}
whereto->adj = linkedAdjacencyList[i];
}
else{linkedAdjacencyList[j]->adj = linkedAdjacencyList[i];}
}
}

帮助!

编辑:根据您的建议,这是新代码,但是现在调用该方法时立即出现段错误?我会发布电话...
int edges;
in >> edges;
g.edges = edges;
for(int i = 0; i < edges; i++)
{
int first;
int second;
in >> first >> second;
g.addEdge(first, second);
}

1 Câu trả lời

我建议 linkedAdjacencyList[i]trở lại VÔ GIÁ TRỊ ,所以你试图取消引用 VÔ GIÁ TRỊ .只需为 VÔ GIÁ TRỊ 添加额外检查:

Node* whereto = NULL;
whereto = linkedAdjacencyList[i];
if (NULL != whereto){
while(whereto->adj != NULL) .....

关于null - NULL 检查中的段错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5643854/

31 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com