将指针数组传递给函数参数

问题描述

我正在尝试使用相邻链表图数据结构构建一个总线网络。 简化代码如下所示:

typedef struct BusNetwork
{
    struct AdjStopList *stopsArray;  //defing the array of pointers
} BusNetwork;

typedef struct Node
{
    int stopID;
    struct Node *next;
} Node;

typedef struct AdjStopList
{
    char stopName[20];
    int numOfAdjStp;
    struct Node *first;
} AdjStopList;

void insertStopAtLast(AdjStopList *L,int stopID)
{
    //add stopID to the last node of the list
    return;
}

void addBusRoute(AdjStopList *L[],int from,int to)
{
    if (from == to)
        return;

    insertStopAtLast(L[from],to);
    return;
}

void main(BusNetwork *BN,int to)
{
    addBusRoute(BN->stopsArray,from,to);
}

问题在于 addBusRoute(BN->stopsArray,to); 似乎我没有传递与函数参数相同类型的值。但是我对BN->stopsArray的理解是一个指针数组,应该和AdjStopList L[]是一样的。出了什么问题?

解决方法

参数 AdjStopList *L[]AdjStopList **L 的含义相同。

另一方面,传递的 BN->stopsArraystruct AdjStopList *

参数是指向指向 AdjStopList的指针,但传递的是指向AdjStopList的指针。

因此,类型不同。