【发布时间】:2019-04-10 21:26:39
【问题描述】:
我试图为链表做一个参数化构造函数我的程序即将通过使用一个喜欢的列表来实现一个队列所以我想做一个像 Queue(int value , int size) 这样的参数化构造函数并且它不会运行或做一个清单 这是我解决这个问题的代码
Queue(int value,int _size)
{
for(int i = 0; i < _size; ++i)
{
Node* temp = new Node;
temp->data = value;
temp->next = nullptr;
if(head == nullptr)
{
head = tail = temp;
}
else
{
tail->next = temp;
tail = temp;
}
}
}
我希望结果是按值乘以大小来填充 lest,就像我运行这个函数 Queue x(20,3) 链接列表应该是 20 20 20
【问题讨论】:
标签: class c++11 linked-list queue