如何使用链接列表插入功能访问另一个类?

如何解决如何使用链接列表插入功能访问另一个类?

我有一个现有程序,该程序带有5个参数的输入。输入的是视频标题,URL,评论,长度和等级。全部包含在video.cppvideo.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 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?