c++ BST和文件处理
c++ BST and file handling
我有兴趣创建一个汽车注册程序:
菜单供用户添加、删除、查找、编辑(更改有关汽车的特定细节)汽车和查看所有汽车。然后使用二叉搜索树将其存储在内存中。所有的汽车都将从内存写入CSV文件中。此外,当加载系统时,它应该读取所有的汽车返回
汽车有汽油和电动两种。每辆车都有属性车名,车主,品牌,型号,号牌一辆汽油车加满油后有里程属性电动汽车有属性power, miles
class car
{
string id
string owner
string make
string model
string numberplate
virtual getkey()//gets key being searched etc.
readfile();
writefile();
};
class petrol : public car
{
string miles
string topup
};
class electric : public car
{
string power
string miles
};
data structure:
class node
{
car *ptr
node *left
node *right
};
class tree
{
///insert delete etc.
};
这是一个实用的类设计吗?可能需要包含哪些函数?
初始BST和链表实现的问题是,它们要么强制您使用特定的数据类型,要么继承该数据类型(例如您的数据类型)。如果我想要水果的BST,我不能用你的树,因为你的树是专门用于汽车的。
我建议一个抽象节点类,并从节点类派生你的数据类:
struct Node
{
boost::shared_ptr<Node> left;
boost::shared_ptr<Node> right;
// Interface functions for descendants
virtual bool is_less_than(boost::shared_ptr<Node> other_node) const = 0;
virtual bool is_equal_to(boost::shared_ptr<Node> other_node) const = 0;
};
我仍然认为最好的设计是使用模板:
template <class User_Data_Type>
class Node
{
public:
boost::shared_ptr<Node> left;
boost::shared_ptr<Node> right;
User_Data_Type m_data;
};
相关文章:
- 如何在 c++ 窗口中将参数和返回的退出值传递到批处理文件/从批处理文件获取返回的退出值
- 从之前添加的批处理文件中删除单词
- 无法从C++ Windows 服务执行批处理文件
- 处理文件期间输出失真.wav
- TOCTTOU - 在处理文件之前使用访问权限
- 如何将批处理文件的输出读取到C 中的字符串中
- cmake:生成批处理文件调用cl.exe
- 处理文件行流迭代器
- 如何运行批处理文件和读取输出
- 用文本处理文件
- GetCommandLine():无法从批处理文件(GCC-Compiler)传递多行参数
- exe文件不被识别为内部或外部命令,可操作的程序或批处理文件在C++
- 您如何使用System()调用带有引号的参数的批处理文件
- Visual Studio C - 无法输出预处理文件
- 重命名批处理文件(删除名称中的一些符号)(python/matlab/shell)
- Dokan:我应该自己处理文件共享和访问权限吗?
- C++处理文件,在制作程序时遇到麻烦
- 对桌面进行了更改.ini使用批处理文件,但文件夹图标不会更改
- 如何将字符串转换为批处理文件中的整数
- 为什么我不能在Windows Server 2008中使用System()从服务启动批处理文件