C++ 创建用于存储队列的向量

C++ 创建用于存储队列的向量,c++,xcode,vector,queue,C++,Xcode,Vector,Queue,我真的很难在我的程序中实现一个向量来存储我的数据和优先级,以便以后可以访问它们。我试过几种方法,但都会导致一些错误,有人能帮我一下吗。任何帮助都将不胜感激 #include <iostream> #include <string> #include <vector> using namespace std; template <class T1> class PriQueue { public: vector<T1>

我真的很难在我的程序中实现一个向量来存储我的数据和优先级,以便以后可以访问它们。我试过几种方法,但都会导致一些错误,有人能帮我一下吗。任何帮助都将不胜感激

#include <iostream>
#include <string>
#include <vector>

using namespace std;

template <class T1>
class PriQueue
{
    public:

    vector<T1> tasks; // My vector which does absolutely NOTHING right now

    PriQueue();
    void enqueue(T1 str, int pri); //Adds to queue
    void setStr(T1 newStr);
    void setPri(int newPri);
    T1 getStr();
    T1 getPri();
    void dequeue(T1 str, int pri); //Deletes from queue
    void peek(); //Prints the the first in queue
    void size(); //Prints how many in queue

    //T1 printQ();

    private:

    T1 s;
    T1 p;

};

template <class T1>
PriQueue<T1>::PriQueue()
{

}

template <class T1>
void PriQueue<T1>::enqueue(T1 str, int pri) //Adding an element to the queue
{
    this->s = str;
    this->p = pri;
    tasks.push_back(s); //If I do this, how would I print the front most item?
    tasks.push_back(p);

}

template <class T1>
void PriQueue<T1>::setStr(T1 newStr)
{


    this->s = newStr;


}

template <class T1>
void PriQueue<T1>::setPri(int newPri)
{

    this->p = newPri;


}

template <class T1>
T1 PriQueue<T1>::getStr()
{
    return s;

}

template <class T1>
T1 PriQueue<T1>::getPri()
{
    return p;

}

template <class T1>
void PriQueue<T1>::dequeue(T1 str, int pri) //Removing an element from the front of the queue
{


}

template <class T1>
void PriQueue<T1>::peek() //Returning a value at front of the queue (NOT removing it)
{
    for (auto& v : tasks)
    cout << v << endl;

}

template <class T1>
void PriQueue<T1>::size() //Returning the number of items in the queue.
{


}


int main()
{
    string more;
    string task;
    int priority;

    do {

        PriQueue<string> que;

        cout << "What is your task in one word?" << endl;
        cin >> task;
        que.setStr(task);

        cout << "What is the priority level of the task on a scale of 1 to 10 (1 has the highest priority)?" << endl;
        cin >> priority;
        que.setPri(priority);


        //cout << que.getStr() << endl; //Test #1
        //cout << que.getPri() << endl; //Test #2

        cout << "Would you like to add another task (y/n)?" << endl;
        cin >> more;


    } while (more == "y" || more == "Y" || more == "Yes" || more == "yes");

que.peek();

return 0;
}
#包括
#包括
#包括
使用名称空间std;
样板
类优先级队列
{
公众:
vector tasks;//我的vector现在什么都不做
PriQueue();
void enqueue(T1 str,int pri);//添加到队列
无效设置TR(T1新闻TR);
无效setPri(int newPri);
T1 getStr();
T1 getPri();
void dequeue(T1 str,int pri);//从队列中删除
void peek();//打印队列中的第一个
void size();//打印队列中的数量
//T1 printQ();
私人:
T1-s;
T1-p;
};
样板
PriQueue::PriQueue()
{
}
样板
void PriQueue::enqueue(T1 str,int pri)//向队列添加元素
{
这->s=str;
这->p=pri;
tasks.push_back(s);//如果这样做,如何打印最前面的项目?
任务。推回(p);
}
样板
void PriQueue::setStr(T1 newStr)
{
这->s=newStr;
}
样板
void PriQueue::setPri(int newPri)
{
这->p=newPri;
}
样板
T1 PriQueue::getStr()
{
返回s;
}
样板
T1 PriQueue::getPri()
{
返回p;
}
样板
void PriQueue::dequeue(T1 str,int pri)//从队列前面移除元素
{
}
样板
void PriQueue::peek()//在队列前面返回一个值(不删除它)
{
用于(自动和验证:任务)

需要明确的是,这是一项学校作业,你不能只使用
std::priority\u queue
?另外,请正确缩进你的代码。你尝试了一下很好,但你应该准确地列出错误是什么,你希望/预期会发生什么,你不了解如何实现这一点……@TonyD让我们说我实现了list.push\b在我的队列函数中,我将如何打印所有存储在我的向量中的文件?@ USER 260739——不要调用你的成员变量<代码>列表< /> >。已经有了<代码> STD::C++中的列表< /Cord>容器。@ PaulMcKeZii我相信评论是为我准备的,我现在就要做了。