自己的C++列表类实现(插入函数)出现问题
Trouble with own C++ list class implementation (insert function)
我即将实现我自己的基本数据结构。这是一类列表。我正在努力修复插入(int 数据(。
想法:每个元素都有一个值和 3 个指针:指针 1:头部:指向头部单元格指针 2:当前:指向当前单元格指针3:下一页: 指向邻居元素的结构
每当我们将新元素放入列表中时,我已经尝试了 next = &date。在此处输入代码'
class list{
private:
typedef struct element{
int wert;
element *next;};
element *current;
element *head;
public://constructur.
list()
{head=new element; current=head; head->next=0;}
/*A new element with value is beeing inserted */
void insert (int value){
next= &value;}
};
void insert (int value){
struct element* new_node = (struct element*) malloc(sizeof(struct element));
new_node->wert = value;
new_node->next = head;
head = new_node;
}
现在它起作用了。
您将列表结构与节点结构混合在一起。对于列表,您需要这样的东西:
class list {
node* head;
}
然后对于列表中您需要的注释
class node {
element* currentData;
node* next;
}
因此,这里的节点组成了列表结构,而存储在列表中的数据具有类型"element"。
相关文章:
- 类C++中的函数问题(LNK2019和LNK1120错误)
- 返回不停止函数,递归函数问题?(编程练习,动态规划,Levenshtein 回溯)
- 变分模板递归构造函数问题
- C++函数问题中的数组分配
- C++中嵌套在另一个 LinkedList 中的 LinkedList 整数上的回调函数问题
- C++重载构造函数问题
- 二叉搜索树析构函数问题
- C++ vector<pair<int,int>> std::all_of() 函数问题(重定向到头文件)
- 迷宫构造函数问题 [线程 1:EXC_BAD_ACCESS(代码 = 1,地址 = 0x8)]
- C++函数问题中的 IF 语句
- 函数问题,未定义的引用错误
- C++ 指针无效函数问题
- C++函数问题 = 帮助我理解基本概念
- 由于基于接口的编程,遇到 C++ 虚拟模板函数问题
- C++二进制树递归析构函数问题
- 构造函数问题<无法读取内存>
- 构造函数问题
- C 时间函数问题
- 另一个类中的类的构造函数问题
- C与C++函数问题