20160213.CCPP体系详解(0023天)
程序片段(01):全排列.c
内容概要:全排列密码库
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
//01.对于字符类型的数组进行初始化特点:
// 如果赋予的数据是字符串,则可以省略掉大括号
//注:性能+最优
int main01(void)
{
char arr[10] = "11111";
for (char * p = arr; 0 != *p; ++p)
{
putchar(*p);
}
system("pause");
}
//02.凡是涉及到跨函数修改数据:
// 注:必须传递变量的所属地址!
void swop(char * pa, char * pb)
{
char temp = *pa;
*pa = *pb;
*pb = temp;
}
//03.全局变量的使用:
// 导致:每次操作的都是同一个变量!
int ipos = 0;
char srcStr[5] = "1234";
void allArange(char * pBegin)
{
if ('\0' == *pBegin)
{
printf("第%2d次排列,排列结果为%4s! \n", ++ipos, srcStr);
char resPath[100] = { 0 };
sprintf(resPath, "echo %s >> E:\\Resource\\TestData\\Test\\allArange.txt", srcStr);
system(resPath);
}
for (char * p = pBegin; '\0' != *p; ++p)
{
swop(pBegin, p);
allArange(pBegin + 1);
swop(p, pBegin);
}
}
int main(void)
{
allArange(srcStr);
system("pause");
}
程序片段(02):快速排序法
内容概要:快速排序法
#include <stdio.h>
#include <stdlib.h>
void swop(int * pa, int * pb)
{
int temp = *pa;
*pa = *pb;
*pb = temp;
}
void show(int * arr, int n)
{
for (int i = 0; i < n; ++i)
{
printf("%3d", arr[i]);
}
printf("\n");
}
//01.快速排序:
// 用途:单线程整体数据排序最快!
void quick(int * arr, int leftIndex, int rightIndex)
{
int i = leftIndex;
int j = rightIndex + 1;
if (i < j)//保证索引正确!+排除第一次异常!
{
do
{
do
{
++i;//跳过待中立的数组元素
} while (i <= rightIndex && arr[i] <= arr[leftIndex]);//找到从左边开始的第一个小于或等于数组首元素的的数组元素
do
{
--j;//进入到真实的数组元素
} while (j > leftIndex && arr[j] >= arr[leftIndex]);//找到从右边开始的第一个大于或等于首元素的数组元素
if (i < j)
{
swop(&arr[i], &arr[j]);//交换(最靠左边的第一个小于值和最靠右边的第一个的大于值)!
}
} while (i < j);//一轮交换完毕!
swop(&arr[leftIndex], &arr[j]);
quick(arr, leftIndex, j - 1);
quick(arr, j + 1, rightIndex);
}
}
int main01(void)
{
int arr[10] = { 10, 9, 20, 19, 13, 8, 9, 22, 0, 91 };
printf("数组原始状态: \n");
show(arr, 10);
quick(arr, 0, 9);
printf("数组排序之后: \n");
show(arr, 10);
system("pause");
}
20160213.CCPP体系详解(0023天)的更多相关文章
- 20160129.CCPP体系详解(0008天)
程序片段(01):函数.c+call.c+测试.cpp 内容概要:函数 ///函数.c #include <stdio.h> #include <stdlib.h> //01. ...
- 20160226.CCPP体系详解(0036天)
程序片段(01):01.多线程.c+02.多线程操作.c 内容概要:多线程 ///01.多线程.c #include <stdio.h> #include <stdlib.h> ...
- 20160208.CCPP体系详解(0018天)
程序片段(01):main.c 内容概要:PointWithOutInit #include <stdio.h> #include <stdlib.h> //01.野指针详解: ...
- 20160206.CCPP体系详解(0016天)
代码片段(01):.指针.c+02.间接赋值.c 内容概要:内存 ///01.指针 #include <stdio.h> #include <stdlib.h> //01.取地 ...
- 20160205.CCPP体系详解(0015天)
程序片段(01):01.杨辉三角.c 内容概要:杨辉三角 #include <stdio.h> #include <stdlib.h> #define N 10 //01.杨辉 ...
- 20160204.CCPP体系详解(0014天)
程序片段(01):define.h+data.h&data.c+control.h&control.c+view.h&view.c+AI.h&AI.c+main.c 内 ...
- 20160203.CCPP体系详解(0013天)
程序片段(01):数组.c+02.数组初始化语法.c 内容概要:数组 ///01.数组.c #include <stdio.h> #include <stdlib.h> //0 ...
- 20160128.CCPP体系详解(0007天)
以下内容有所摘取,进行了某些整理和补充 论浮点数的存储原理:float浮点数与double浮点数的二进制存储原理–>阶码 浮点数转二进制 1.整数int类型和浮点数float类型都是占用4个字节 ...
- 20160127.CCPP体系详解(0006天)
程序片段(01):msg.c 内容概要:线程概念 #include <stdio.h> #include <stdlib.h> #include <Windows.h&g ...
随机推荐
- ASP.NET CORE系列【五】webapi整理以及RESTful风格化
介绍 什么是RESTful? 这里不多做赘述,详情请百度! 哈哈,本来还想巴拉巴拉介绍一些webapi, RESTful的, 还是算了,咱们直接上干货!(原因是懒!哈哈) 使用 以前使用过mvc的人 ...
- 【推荐】CentOS修复OpenSSH用户枚举漏洞
注:以下所有操作均在CentOS 6.8 x86_64位系统下完成. #漏洞说明# OpenSSH(OpenBSD Secure Shell)是OpenBSD计划组所维护的一套用于安全访问远程计算机的 ...
- 用ECMAScript4 ( ActionScript3) 实现Unity的热更新 -- Demo分析
如何创建工程 下载最新的Unity发布插件包. 打开Unity,新建一个项目 将插件包导入 在菜单中点击ASRuntime/Create ActionScript3 FlashDevelop HotF ...
- [LeetCode] Valid Square 验证正方形
Given the coordinates of four points in 2D space, return whether the four points could construct a s ...
- 机器学习技法:11 Gradient Boosted Decision Tree
Roadmap Adaptive Boosted Decision Tree Optimization View of AdaBoost Gradient Boosting Summary of Ag ...
- [HNOI 2016]网络
Description 一个简单的网络系统可以被描述成一棵无根树.每个节点为一个服务器.连接服务器与服务器的数据线则看做 一条树边.两个服务器进行数据的交互时,数据会经过连接这两个服务器的路径上的所有 ...
- ●BZOJ 3640 JC的小苹果
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=3640题解: 期望dp,高斯消元 设dp[i][h]在i位置且血量为h这个状态的期望经过次数. ...
- DP测试总结
T1:三取方格数 题目描述 设有N*N的方格图,我们将其中的某些方格填入正整数,而其他的方格中放入0.某人从图得左上角出发,可以向下走,也可以向右走,直到到达右下角.在走过的路上,他取走了方格中的数. ...
- hdu 5636 搜索 BestCoder Round #74 (div.2)
Shortest Path Accepts: 40 Submissions: 610 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: ...
- 树链剖分模板(BZOJ3083)
实现了路径修改,子树查询,及换根. 换根其实很简单,分三种情况讨论,画画图就明白了. #include <cstdio> #include <algorithm> using ...