这是迭代通过指向c中结构中指针的指针的正确方法吗?

时间:2015-06-04 07:32:50

标签: c pointers

这是否正朝着正确的方向发展?我之前遇到过段错误,但现在我无法判断这是否正在做我认为它正在做的事情。 Vertex结构有一个指向指针数组的指针,该指针数组指向与它相邻的其他Vertex结构。我需要遍历这些邻居。

//v is pointer to a Vertex
for(int i = 0; i < v->numNeighbors; i++)
{
    //if(!(inCirDeque(c, v->neighbors[i])))
    if(!(inCirDeque(c, &(*((*v).neighbors)[i] )) ))
    {                       
        //addBackCirListDeque(c, v->neighbors[i]);
        addBackCirListDeque(c, &( *((*v).neighbors)[i]));
    }
}


/* Double Link Struture */
struct DLink {
  TYPE value;           /* value of the link */
  struct DLink * next;  /* pointer to the next link */
  struct DLink * prev;  /* pointer to the previous link */
};

/* Deque Structure based on Circularly-Doubly-Linked List */
struct cirListDeque {
  int size;             /* number of links in the deque */
  struct DLink *last;   /* pointer to the last link */
};
typedef struct cirListDeque cirListDeque;

struct Vertex {
    char label;
    int isVisited; /* Use this boolean to remember where you have been */

    int numNeighbors;
    struct Vertex** neighbors; /* array of pointers to Vertex which are adjacent to THIS */
};
typedef struct Vertex Vertex;

0 个答案:

没有答案