摘要:
题目:把一个有序整数数组放到二叉树。答:#include "stdafx.h"#include <iostream>using namespace std;struct TreeNode { int m_nValue; TreeNode *m_pLeft; TreeNode *m_pRight;};//把一个有序整数数组放到二叉树void RecurCreateTree(int *p, int length, TreeNode *&pHead){ if (length > 0) { pHead = new TreeNode; int m... 阅读全文
摘要:
题目:从扑克牌中随机抽5张牌,判断是不是一个顺子,即这5张牌是不是连续的。2-10为数字本身,A为1,J为11,Q为12,K为13,而大小王可以看成任意数字。答:#include "stdafx.h"#include <iostream>#include <ctime>using namespace std;#define MAXVALUE 10000#define MINVALUE -1#define SIZE 14 #define NUMBER 5//扑克牌的顺子bool IsSort(int arr[], int length){ int pl 阅读全文
摘要:
题目:二叉树的结点的定义如下:struct TreeNode { int m_nValue; TreeNode *m_pLeft; TreeNode *m_pRight;};输入二叉树中的两个结点,输出这两个结点在数中最低的共同父结点。答:#include "stdafx.h"#include <iostream>#include <fstream>#include <ctime>using namespace std;struct TreeNode { int m_nValue; TreeNode *m_pLeft; TreeNode 阅读全文