C、打印字符串链表 [英] C, Print Linked List of Strings

查看:37
本文介绍了C、打印字符串链表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have to write a C program that uses a linked list. I have created a list and added elements to the list. But I don't know how to print all the elements in the list. The list is a list of strings. I figured I'd somehow increment through the list, printing every string that's there, but I can't figure out a way to do this.

简短:如何打印链表?

推荐答案

没有愚蠢的问题1.下面是一些帮助您入门的伪代码:

There are no stupid questions1. Here's some pseudo-code to get you started:

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

printAll (head)

就是这样,从头节点开始,打印出有效负载并移动到列表中的下一个节点.

That's it really, just start at the head node, printing out the payload and moving to the next node in the list.

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

Once that next node is the end of the list, stop.

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

1 Well, actually, there probably are, but this isn't one of them :-)

这篇关于C、打印字符串链表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆