ASP源码.NET源码PHP源码JSP源码JAVA源码DELPHI源码PB源码VC源码VB源码Android源码
当前位置:首页 >> 低调看直播体育app软件下载 >> 其他编程jrs看球网直播吧_低调看直播体育app软件下载_低调看体育直播 >> 0907-象棋五子棋代码分析/寻找算法以及排序算法

0907-象棋五子棋代码分析/寻找算法以及排序算法(6/6)

来源:网络整理     时间:2016-03-04     关键词:

本篇文章主要介绍了"0907-象棋五子棋代码分析/寻找算法以及排序算法",主要涉及到方面的内容,对于其他编程jrs看球网直播吧_低调看直播体育app软件下载_低调看体育直播感兴趣的同学可以参考一下: 象棋五子棋代码分析编译代码报错:错误 1 error MSB8031: Building an MFC project for a non-Unicode ch...

#include 
#include

using namespace std;
const int N = 10;
void shell_sort(const int len, int *array)
{
	int j, i, key;
	int gap = 0;
	if (len <= 0 || array == NULL)
		return;
	while (gap <= len)
	{
		gap = gap * 3 + 1;
	}
	while (gap > 0)
	{
		for (i = gap; i < len; i++)
		{
			j = i - gap;
			key = array[i];
			while ((j >= 0) && (array[j] > key))
			{
				array[j + gap] = array[j];
				j = j - gap;
			}
			array[j + gap] = key;
		}
		//display_array(len,array,gap);
		gap = (gap - 1) / 3;
	}
}

// 3  5  18   29     35   24   12  0
// 3                           12   
//     5                            0
// 3   0  18  29    35    24  12    5
//3                       24
//    0                       12
//        18                        5
//3   0   5  29     35    24  12    18
//3                  35
//   0                   24
//       5                   12
//           29                     18
//3  0   5   18   35   24   12     29   
//3          18             12
//   0            35               29
//        5            24
//3  0    5  12   29   24      18   35
//3       5       29            18
//   0        12        24          35
//3   0   5   12     18    24        29 35
//0    3  5 12    18  24   29  35

int main4()
{
	int array[N];
	for (int i = 0; i < 10; i++)
	{
		array[i] = rand() % 100;
		cout << array[i] << " ";
	}
	shell_sort(N - 1, array);
	cout << endl;
	for (int i = 0; i < 10; i++)
	{

		cout << array[i] << " ";
	}
	system("pause");
	return 0;
}

选择.cpp

#include 
using namespace std;

void main2()
{
	int a[10];
	for (int i = 0; i < 10; i++)
		a[i] = rand() % 100;

	for (int i = 0; i < 10; i++)
	{

		for (int j = i; j < 10 - i; j++)
			if (a[j] < a[i])
			{
			int temp = a[j];
			a[j] = a[i];
			a[i] = temp;
			}
	}

	for (int i = 0; i < 10; i++)
		cout << a[i] << " ";
	system("pause");
}

以上就介绍了0907-象棋五子棋代码分析/寻找算法以及排序算法,包括了方面的内容,希望对其他编程jrs看球网直播吧_低调看直播体育app软件下载_低调看体育直播有兴趣的朋友有所帮助。

本文网址链接:http://www.codes51.com/article/detail_361885_6.html

相关图片

相关文章