编译时错误
hpp文件:
https://paste.ubuntu.com/p/xBZB8K6s3m/
cpp
https://paste.ubuntu.com/p/WYpRgjTFf2/
不采纳复制粘贴网络链接,答案
#include "messageBox.hpp"
#include <iostream>
//#include <string>
#include <map>
using namespace std;
messageBox::messageBox()
{
waitNum = 1;
}
void messageBox::receive(int num)
{
Node* cur = new Node(num);
headmap.insert(num, cur);
tailmap.insert(num, cur);
//找到上一个尾节点
if(tailmap.find(num-1) != tailmap.end())
{
tailmap.at(num-1) -> next = cur;
tailmap.erase(num-1);
headmap.at(num-1)->next = cur;
headmap.erase(num);
}
//找到下一个头节点
if(headmap.find(num+1) != headmap.end())
{
cur -> next = headmap.at(num+1);
headmap.erase(num+1);
cur -> next = tailmap.at(num+1);
tailmap.erase(num+1);
}
if(waitNum == num)
{
print();
}
}
void print()
{
struct Node* tempnode = headmap.at(waitNum);
headmap.erase(waitNum);
while(tempnode != NULL)
{
cout << tempnode -> index << endl;
tempnode = tempnode -> next;
waitNum++;
}
tailmap.erase(--waitNum);
}
int main()
{
messageBox msnbox;
msnbox.receive(2);
msnbox.receive(1);
msnbox.receive(4);
msnbox.receive(5);
msnbox.receive(7);
msnbox.receive(8);
msnbox.receive(6);
msnbox.receive(3);
msnbox.receive(9);
msnbox.receive(10);
msnbox.receive(12);
msnbox.receive(13);
msnbox.receive(11);
}
#ifndef MESSAGEBOX_HPP
#define MESSAGEBOX_HPP
#include <map>
//#include <string>
using namespace std;
struct Node
{
int index;
Node* next;
Node(int i)
{
index = i;
next = NULL;
}
};
class messageBox
{
private:
map<int, Node*> headmap;
map<int, Node*> tailmap;
int waitNum;
public:
messageBox();
void receive(int num);
void print();
};
#endif