摘要: 题目:对于一颗完全二叉树,要求给所有节点加上一个pNext指针,指向同一层的相邻节点;如果当前节点已经是该层的最后一个节点,则将pNext指针指向NULL;给出程序实现,并分析时间复杂度和空间复杂度。答:时间复杂度为O(n),空间复杂度为O(1)。#include "stdafx.h"#include <iostream>#include <fstream>#include <vector>using namespace std;struct TreeNode { int m_nValue; TreeNode *m_pLeft; Tree 阅读全文
posted @ 2012-09-04 19:36 venow 阅读(1026) 评论(0) 推荐(0)
摘要: #include "stdafx.h"#include <iostream>using namespace std;#define MAXSIZE 20typedef struct{ int r[MAXSIZE + 1]; int length;}SqList;//***********************************起泡排序*************************************beginvoid BubbleSort(SqList& L){ bool flag = false; for (int i = L.leng 阅读全文
posted @ 2012-09-04 19:27 venow 阅读(475) 评论(0) 推荐(0)
摘要: 题目:输入两个整数n和m,从数列1,2,3.....n中随意曲几个数,使其和等于m,要求将其中所有的可能组合列出来。答:#include "stdafx.h"#include <iostream>#include<list> using namespace std;//1到N中所有和为M的组合void FindAllCombinationEqualM(list<int> &l, int m, int n){ if (m <= 0 || n <= 0) { return; } if (m == n) { for (lis 阅读全文
posted @ 2012-09-04 19:23 venow 阅读(1135) 评论(0) 推荐(0)
摘要: 题目:请使用代码计算1234567891011121314151617181920*2019181716151413121110987654321。答:#include "stdafx.h"#include <iostream>#include <string>using namespace std;int _tmain(int argc, _TCHAR* argv[]){ string strOne; string strTwo; cout<<"输入第一个乘数:"; cin>>strOne; cout&l 阅读全文
posted @ 2012-09-04 19:15 venow 阅读(760) 评论(2) 推荐(0)