基本的简单题目,很适合数据结构入门用,基本就是先中后遍历、层序遍历、测树的高度、打印树的左右侧节点、插入、交换子树、哈夫曼解码等等基础操作
难度是Moderate的
1.Tree: Huffman Decoding
/*
名称:Tree: Huffman Decoding
难度:Moderate
类别:/
思路:题目本身不难,弄懂题意就好:按照他的意思将哈夫曼编码解码即可
*/
#include<iostream>
#include<string>
using namespace std;
struct node
{
int freq;
char data;
node * left;
node * right;
};
void decode_huff(node* root,string s)
{
int i = 0;
node* temp=root;
string result = "";
while (i < s.length())
{
while (temp->data == '\0')
{
if (s[i] == '1')
{
temp = temp->right;
i++;
}
else
{
temp = temp->left;
i++;
}
}
result =result+temp->data;
temp = root;
}
cout << result;
}
int main()
{
char a = '\0';
cout << a;
return 0;
}
比较综合的
1.Swap Nodes [Algo]
/*
名称:Swap Nodes [Algo]
难度:Easy
类别:/
思路:题目本身也不难,但把建树、交换。遍历融合一起用(感觉像是期末考试题)
*/
#include<iostream>
#include <cstdlib>
using namespace std;
struct Node
{
int data;
int height;
Node *left;
Node *right;
};
Node* Create(Node *root)
{
int N;
int left, right;
int front = 0, rear = 0;
Node *queue[2000];
queue[rear++] = root;
cin >> N;
for (int i = 0; i < N; i++)
{
Node *Leftchild = NULL, *Rightchild = NULL;
Node *parent = queue[front++];
cin >>