弄清楚链表的插入函数参数
Figuring out Insert function parameter for linked list?
我的老师给一个司机上课来完成一个程序,我不确定如何编写插入函数。
给我带来麻烦的台词:
you.Insert(me,0);
you
用于默认构造函数,me
用于显式值构造函数,因此此行应该创建一个包含 me
内容的 you
节点。
我迷失了如何编写参数来访问我的插入函数
void WRD::Insert( ?, int new_data)
我将包括我拥有的显式构造函数,任何在心理上理解这一点的见解都会有所帮助。(包括insert
应该是什么样子或根据我给出的示例做什么的示例。
WRD::WRD(const string & s)
{
cout<<"one calledn";
front = 0;
for(unsigned i=0; i<s.length(); i++)
{
AddChar(s[i]);
}
}
class node
{
public:
char symbol;
node * next;
};
v
oid Insert(node * &ptr, int new_data)
{
node *new_ptr = new node;
new_ptr -> data = new_data;
new_ptr -> next = 0; //always initialize a pointer
if (Empty(ptr))
{
ptr = new_ptr;
}
else if (new_ptr->data <= ptr->data)
{
new_ptr->next = ptr;
ptr = new_ptr;
}
else
{
node *fwd_ptr=ptr, *pre_ptr=ptr;
while(fwd_ptr!=0 && (fwd_ptr->data < new_ptr->data))
{
pre_ptr = fwd_ptr;
fwd_ptr = fwd_ptr->next;
}
if (fwd_ptr == 0)
{
pre_ptr->next = new_ptr;
}
else
{
new_ptr->next = fwd_ptr;
pre_ptr->next = new_ptr;
}
}
}
像这样我想(假设我理解你没错(
void WRD::Insert(const WRD& w, int new_data)
展示更多驱动程序程序可能会有所帮助,尤其是如何声明you
和me
。
相关文章:
- static_assert在宏中,但也可以扩展到可以用作函数参数的东西
- C++中的高效循环缓冲区,它将被传递给C样式数组函数参数
- 当从函数参数中的临时值调用复制构造函数时
- 如何从"decltype()"获取函数参数的数量<funtion>?
- 如何将lambda作为模板类的成员函数参数
- 模板参数推导失败,函数参数/参数不匹配
- 如何在C++中将迭代器作为函数参数传递
- 将函数参数"const char*"转换为"std::string_view"是
- C++ 如何将数组值解压缩为函数参数
- 主函数参数的属性
- 具有两个间接寻址运算符 (C++) 的函数参数的用途
- "Warning: Comma within array index expression"但逗号分隔函数参数
- 如何定义在用作函数参数时工作的类模板的转换
- 将函数参数完美转发到函数指针:按值传递呢?
- 为什么我不能将引用作为 std::async 的函数参数传递
- 什么..(省略号)作为函数原型中唯一的函数参数,C++?
- 是否可以就地构造一个固定大小的数组作为函数参数?
- 接受模板作为函数参数
- 将成员函数作为构造函数参数调用时出错 "Variable is not a type name"
- Arduino 函数参数