小编Tót*_*ila的帖子

打印函数链表 C++

我目前正在学习 C++ 中的链表,我无法编写打印列表元素的打印函数;我的意思是我写了这个函数,但它不能正常工作。

#include <iostream>

using namespace std;

struct node
{
    char name[20];
    node* next;
};

node* addNewPerson(node* head)
{
    node* person = new node;

    cout << "Name: ";
    cin >> person->name;

    person->next = NULL;

    if (head == NULL) //is empty
    {
        head = person;
    }

    else
    {
        person = person->next;
    }

    return head;
}

void printList(node* head)
{
    node* temp = head;

    cout << temp->name << endl;
}

int main()
{
    node* head = NULL;

    node* temp = head; …
Run Code Online (Sandbox Code Playgroud)

c++ printing function linked-list

2
推荐指数
1
解决办法
4万
查看次数

标签 统计

c++ ×1

function ×1

linked-list ×1

printing ×1