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

查看:274
本文介绍了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 。下面是一些伪code,让你开始:

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天全站免登陆