如何解决如何使用链接列表插入功能访问另一个类?
我有一个现有程序,该程序带有5个参数的输入。输入的是视频标题,URL,评论,长度和等级。全部包含在video.cpp
和video.h
中。
我的新任务是根据视频标题,按排序的顺序将每个视频插入到链接列表中。
我的问题是我不知道如何从我的class Video
函数访问void Vlist::Insert()
及其参数...?
这是我到目前为止所拥有的...
vlist.cpp:
#include <iostream>
#include <algorithm>
using namespace std;
#include "vlist.h"
#include "video.h"
void Vlist::Insert(Video)
{
if (m_head == NULL || m_head->m_video > video) {
// Insert before head...
m_head = new Node(video,m_head);
} else {
// Insert after existing node...
Node *node = m_head;
while (node->m_video != NULL && node->m_next->m_video < video) {
node = node->m_next;
}
node->m_next = new Node(video,node->m_next);
}
}
vlist.h:
#ifndef VLIST_H
#define VLIST_H
using namespace std;
class Vlist {
public:
Vlist() {m_head = nullptr; }
void Insert(Video);
private:
class Node {
public:
Node(Video *video,Node *next) {m_video = video; m_next = next; }
Video *m_video;
Node *m_next;
};
Node *m_head;
};
#endif
video.h:
#ifndef VIDEO_H
#define VIDEO_H
using namespace std;
class Video {
public:
Video(string video_title,string video_link,string video_comment,double video_length,int video_number);
void print();
bool Title(Video *spare);
private:
string name;
string web;
string note;
double duration;
int score;
string title;
};
#endif
video.cpp:
#include <iostream>
#include <algorithm>
using namespace std;
#include "video.h"
Video::Video(string video_title,int video_number)
: title(video_title),link(video_link),comment(video_comment),length(video_length),rating(video_number)
{
name = title;
}
bool Video::Title(Video *spare)
{
return name > spare-> name;
}
void Video::print(){
string hierarchy;
switch(rating){
case 1:
hierarchy = "*";
break;
case 2:
hierarchy = "**";
break;
case 3:
hierarchy = "***";
break;
case 4:
hierarchy = "****";
break;
case 5:
hierarchy = "*****";
break;
}
cout << title << "," << link << "," << comment << "," << length << "," << hierarchy << endl;
}
我尝试过void Vlist::Insert(Video)
,void Vlist::Insert(Video *video)
,void Vlist::Insert(m_video)
,但老实说我不知道自己在做什么。这对我来说是全新的。任何帮助将不胜感激。
注意:我意识到我还没有完成链表,我只是 试图分部分工作。
解决方法
var data= [
{
"question": "1.1","level": 1,"id": 4,"answers": [
{
"text_answer": "NO","questions": [
{
"question": "1.1.1","level": 2,"id": 3,"answers": []
}
]
},{
"text_answer": null,"questions": [
{
"question": "1.1.2","id": 2,"answers": [
{
"text_answer": "SI","questions": [
{
"question": "1.1.2.1","level": 3,"id": 1,"answers": []
}
]
}
]
}
]
}
]
}
]
/* [
{
"question": "1.1","children": [
{
"question": "1.1.1","text_answer": "NO","children": []
},{
"question": "1.1.2","text_answer": null,"children": [
{
"question": "1.1.2.1","text_answer": "SI","children": []
}
]
}
]
}
]
*/
function format(d) {
if (d.answers) {
d.answers.forEach((d) => {
format;
});
}
}
format(data);
**note:**
I changed the previous structure that I put to the question to make myself understand better.
的成员是私人的。除非该类公开了公共的访问器函数。
Video
然后在您的列表中:
class Video
{
public:
const std::string& GetTitle() const { return title; }
// ...
private:
std::string title;
};
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。