分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow
也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!
题目
解决代码及点评
- <code class="language-cpp">/*
- 希尔排序
- */
- #include <iostream>
- 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;
- }
- }
- int main()
- {
- 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;
- }
- </code>
/* 希尔排序*/#include <iostream>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; }}int main(){ 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;}
代码下载及其运行
代码下载地址:http://download.csdn.net/detail/yincheng01/6704519
解压密码:c.itcast.cn
下载代码并解压后,用VC2013打开interview.sln,并设置对应的启动项目后,点击运行即可,具体步骤如下:
1)设置启动项目:右键点击解决方案,在弹出菜单中选择“设置启动项目”
2)在下拉框中选择相应项目,项目名和博客编号一致
3)点击“本地Windows调试器”运行
程序运行结果