对于我们最后一个学期的项目,操作系统类中的每个人都负责实现一个伪“linux文件系统”。这个想法是模拟处理文件,文件夹,更改目录等等。C中的结构,指针和树木
我不喜欢在C语言编程时不得不使用字符串和指针,但不幸的是,为了我的和平,这个项目看起来涉及到两者。因为我对指针相当不舒服,所以我希望能够通过一个理智的检查来确定底层树结构的后端实现是否正确。
typedef struct floorNode
{
char floorName[30]; //the name of the tree node
struct floorNode *parentPointer; //this is a pointer to the parent node. Null for the root node.
struct floorNode *childPointers[10]; //this is an array holding pointers to up to 10 child nodes.
char fileArray[10][30]; //this is an array of 10 'files', each of up to length 30.
//for this assignment, strings are the only type of "file"
} floorNode;
这是实现在C树的正确方法?
如果你不喜欢使用指针,那么你不会在C中做任何事情。顺便说一句,大多数语言都有指针,他们只是试图通过调用引用来隐藏它,但大部分相同的问题都适用。 – 2011-04-29 05:12:39
@mu太短 - 我喜欢参考更好,尽管这可能只是我对他们谈话的更多经验。 – 2011-04-29 05:22:02
所有你想要的只是一个文件系统,它的一个限制是一个目录中必须少于10个文件和子目录。我认为存储节点的绝对名称是没有意义的。我希望你能弄清楚为什么 – 2011-04-29 05:22:13