代码拉取完成,页面将自动刷新
#pragma once
#include <iostream>
#include <cstdlib>
#include <queue>
#include <string>
using namespace std;
namespace simple_gen_list
{
struct SimpleGenListNode
{
static const int ATOM = 1;
static const int LIST = 2;
int type; // 类型
char data; // 数据项
SimpleGenListNode* head; // 表头指针(如果type是LIST_HEAD类型)
SimpleGenListNode* next; // 下一节点
SimpleGenListNode() :type(ATOM),data('\0'),next(NULL),head(NULL){}
explicit SimpleGenListNode(int type, char data = '\0') :type(type), next(NULL), head(NULL), data(data) {}
SimpleGenListNode(const SimpleGenListNode& node)
{
type = node.type;
data = node.data;
head = node.head;
next = node.next;
}
};
}
class SimpleGenList
{
private:
// 广义表结点
simple_gen_list::SimpleGenListNode* list_node_;
// 使用队列创建广义表(递归)
void createByQueueRecursive_(queue<char>& char_queue, simple_gen_list::SimpleGenListNode*& node);
// 子表构造字符队列(递归)
bool toCharQueueRecursive_(queue<char>& char_queue, simple_gen_list::SimpleGenListNode* node);
// 求子表深度(递归)
int subGenListDepthRecursive_(simple_gen_list::SimpleGenListNode* node);
// 求子表长度(递归)
int subGenListLengthRecursive_(simple_gen_list::SimpleGenListNode* node);
public:
SimpleGenList() :list_node_(NULL) {}
// 使用字符串创建广义表
void createByString(const string& gen_list_string);
// 生成字符串
string toString();
// 获取深度
int depth();
// 获取长度
int length();
};
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。