【发布时间】:2020-10-18 20:03:33
【问题描述】:
这是我作为任务给出的问题,但是我收到错误“std::list”:使用类模板需要模板参数列表”。目前我只是想让程序在运行时显示列表。
编写函数 moveNthFront 的定义,该函数将正整数 n 作为参数。该函数将队列的第 n 个元素移到前面。其余元素的顺序保持不变。例如,假设:
队列 = {5, 11, 34, 67, 43, 55} 和 n=3
调用函数 moveNthFront 后: 队列 ={34, 5, 11, 67, 43, 55}。
(i)为静态队列模板类实现上述功能。
(ii)为动态队列模板类实现上述功能
这是我的类头代码:
#include <iostream>
#include <list>
using namespace std;
template <class T>
class Queue {
T QueueList;
T position;
public:
// Constructs the queue class and defined the queue list and value for n
Queue(T list, T n) {
QueueList = list;
position = n;
list = { 5, 11,34,67,43, 55 };
n = 0;
};
T PrintQueue();
T MoveNthFront();
};
template <class T>
T Queue<T>::PrintQueue() {
cout << list;
return;
}
template <class T>
T Queue<T>::MoveNthFront() {
}
这是我的主要功能代码(我知道它不起作用,我只是不知道我需要做什么才能使它起作用,它不完整)
#include <iostream>
#include "Queue.h"
int main() {
int n;
int Queuelist;
Queue<int>;
}
【问题讨论】:
-
如果您在代码中搜索“list”并将所有不代表 std::list 的内容替换为不同的单词会怎样?