为什么我的链表指针没有传递给我的start变量?

时间:2014-10-18 21:35:05

标签: c

所以我有一些包含LinkedList开始指针的struct CAR变量,我不明白为什么我的start在函数addN中当start最初为NULL时没有指向我的指针值。我的开始永远不会改变它因某种原因总是保持为NULL。

void initializeLinkedList(VEHICLE *v, int totalVehicles)
{

    int i;
    int k;
    float distance;
    LLIST* bptr;
    int ldata;

    for(i = 0; i < totalVehicles; i++)
    {
        for(k = 0; k < totalVehicles; k++)
        {


            distance = sqrt(distance(v[i],v[k]));
            printf("distance: %f\n",distance);
            if(distance > 0 && distance < 250)
            {
                addN(v[i],v[k]);
                 printf("vehicle %d has the neighbor", v[i].pid);
                bptr = v[i].start;

                while(bptr)
                {
                    ldata = bptr->data;
                    printf(" vehicle %d", ldata);
                    bptr = bptr->next;


                }
                printf("\n");


            }
        }
    }



}

void addN(CAR i, CAR k)
{

LLIST *ptr = (LLIST *)malloc(sizeof(LLIST));

LLIST *prev = (LLIST *)malloc(sizeof(LLIST));

    if(i.start == NULL)
    {

        ptr->data = k.pid;
        ptr->next = i.start;
        i.start = ptr;
        printf("i start: %s\n", i.start);
    }
    else
    {
        prev = i.start;
        while(prev->next != NULL)
        {
            prev = prev->next;
        }
        ptr->data = k.pid;
        prev->next = ptr;
    }

}

0 个答案:

没有答案