需要帮助打印链表

时间:2013-02-26 17:17:54

标签: c linked-list

当我在main中调用printList函数时,它甚至没有打印出所有的值 值存在(我在printList函数中手动检查)

void printList(listNode *start)
{
    listNode *currentPosition = start->next;


    threadList *t;
    t= currentPosition->tList->next;

    cList *c;
    c = currentPosition->tList->next->cpuList->next;

    if (currentPosition == NULL)
    {
        printf("list is empty\n");
    }
    else
    {
        while (currentPosition != NULL)
        {
            printf("process #: %d # of thread: %d\n",currentPosition->processNumber,currentPosition->numThread);

            while (t != NULL)
            {

                printf("thread #: %d Arrival time: %d # CPU: %d\n",t->threadNumber,t->arrivalTime,t->numCPU);


                while (c != NULL)
                {

                    printf("Burst #: %d CPU Time: %d io Time: %d\n",c->cNum,c->cpuTime,c->ioTime);

                    c=c->next;
                }


                t=t->next;
            }
            currentPosition = currentPosition->next;
        }
    }
}

我所有链表的第一个节点是虚节点。 有人可以帮我弄清楚我哪里出错了吗?

1 个答案:

答案 0 :(得分:1)

printList中,您似乎最初设置了tc,然后再也没有更新它们。

如果你移动

t= currentPosition->tList->next;
c = currentPosition->tList->next->cpuList->next;

的内部
while (currentPosition != NULL) {

然后我认为它会起作用(我没有编译器方便)。