gpt4 book ai didi

c++ - C++中的链表数组

转载 作者:行者123 更新时间:2023-11-28 03:30:16 25 4
gpt4 key购买 nike

大家好,尝试将使用结构数组的旧 C 程序转换为使用链表的 C++ 程序。我是一个完全的 C++ 新手,我对在 C++ 中设置链表的语法有点困惑....这是我的代码:

#include <iostream> 
#include <stdlib.h>
#include <string>
#include <ctype.h>
#include <fstream>

using namespace std;


struct Video {
char video_name[1024];
int ranking; // Number of viewer hits
char url[1024]; // Video URL
struct Video *next; // pointer to Video structure
}


struct Video* Collection = new struct Video;
Collection *head = NULL; // EMPTY linked list

在我的旧程序中,Collection 是一个 Video 数组。如何使 Collection 成为 Video 节点的链表?我目前在最后两行代码中收到错误提示:expected initializer before 'Collection'expected constructor, destructor or type conversion before '*' conversion。我知道我的语法肯定是错误的,但我想我不明白如何在 Collection 中创建视频链接列表...

最佳答案

C++ 的答案是:

struct Video { 
std::string video_name;
int ranking; // Number of viewer hits
std::string url; // Video URL
}

std::list<Video> list_of_videos

关于c++ - C++中的链表数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12764938/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com