【 Algorithm】排序数组中查找和为n的一对数和所有组合

/*************************************************
题目:11.	递增数组中查找和为n的一对数
思路:设置头尾指针,比较两者指向的数之和与sum的大小

****************************************************/
#include"stdafx.h"
#include
using namespace std;

bool FindNums(int arr[],int len,int sum)
{
	bool notfound = true;
	if(arr == NULL || len <1)
		return notfound;
	int *pHead = arr;
	int *pLast = arr+len-1;
	while(pHead < pLast)
	{
		long long cursum = *pHead + *pLast;
		if(cursum == sum)
		{
			notfound =true;
			cout << *pHead <<" "<<*pLast <
/******************************数组——背包问题*************************************** 
	题目:求数组和为定值n的m个数
	思路:典型的背包问题
	 采用
**********************************************************************/  
#include"stdafx.h"
#include
#include
#include
using namespace std;

list ilist;

void Find_factor(int sum,int n)
{
	//递归出口
	if(sum <= 0|| n <= 0)
		return ;
	if(sum == n)//要放的数刚好是满足条件的最后一个数
	{
		for(list::iterator iter = ilist.begin(); iter != ilist.end(); iter++)
			cout << *iter << "+";
		cout << n <> sum;
	cout << "请输入你要从 1.....n 数列中取值的 n:" << endl;
	cin >> n;
	cout << "所有可能的序列,如下:" << endl;
	Find_factor(sum,n);

	system("pause");
	return 0;
}


你可能感兴趣的:(笔试面试知识点总结,Data,Structure)