C,打印链接列表

JC *_*yba 3 c printing linked-list

我必须编写一个使用链表的C程序.我已经创建了一个列表并添加了列表中的元素.但我不知道如何打印列表中的所有元素.该列表是字符串列表.我想我会以某种方式在列表中递增,打印出那里的每一个字符串,但我无法想办法做到这一点.

简短:如何打印linked list

pax*_*blo 11

没有愚蠢的问题1.这里有一些伪代码可以帮助您入门:

def printAll (node):
    while node is not null:
        print node->payload
        node = node->next

printAll (head)
Run Code Online (Sandbox Code Playgroud)

真的,只是从头节点开始,打印出有效载荷并移动到列表中的下一个节点.

一旦下一个节点是列表的结尾,停止.


1嗯,实际上,可能有,但这不是其中之一:-)


Hoà*_*ong 5

您可以使用指针来遍历链接列表。伪代码:

tempPointer = head

while(tempPointer not null) {
  print tempPointer->value;
  tempPointer = tempPointer->next;
}
Run Code Online (Sandbox Code Playgroud)