程序片段(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天)的更多相关文章

  1. 20160129.CCPP体系详解(0008天)

    程序片段(01):函数.c+call.c+测试.cpp 内容概要:函数 ///函数.c #include <stdio.h> #include <stdlib.h> //01. ...

  2. 20160226.CCPP体系详解(0036天)

    程序片段(01):01.多线程.c+02.多线程操作.c 内容概要:多线程 ///01.多线程.c #include <stdio.h> #include <stdlib.h> ...

  3. 20160208.CCPP体系详解(0018天)

    程序片段(01):main.c 内容概要:PointWithOutInit #include <stdio.h> #include <stdlib.h> //01.野指针详解: ...

  4. 20160206.CCPP体系详解(0016天)

    代码片段(01):.指针.c+02.间接赋值.c 内容概要:内存 ///01.指针 #include <stdio.h> #include <stdlib.h> //01.取地 ...

  5. 20160205.CCPP体系详解(0015天)

    程序片段(01):01.杨辉三角.c 内容概要:杨辉三角 #include <stdio.h> #include <stdlib.h> #define N 10 //01.杨辉 ...

  6. 20160204.CCPP体系详解(0014天)

    程序片段(01):define.h+data.h&data.c+control.h&control.c+view.h&view.c+AI.h&AI.c+main.c 内 ...

  7. 20160203.CCPP体系详解(0013天)

    程序片段(01):数组.c+02.数组初始化语法.c 内容概要:数组 ///01.数组.c #include <stdio.h> #include <stdlib.h> //0 ...

  8. 20160128.CCPP体系详解(0007天)

    以下内容有所摘取,进行了某些整理和补充 论浮点数的存储原理:float浮点数与double浮点数的二进制存储原理–>阶码 浮点数转二进制 1.整数int类型和浮点数float类型都是占用4个字节 ...

  9. 20160127.CCPP体系详解(0006天)

    程序片段(01):msg.c 内容概要:线程概念 #include <stdio.h> #include <stdlib.h> #include <Windows.h&g ...

随机推荐

  1. jquery楼层效果

  2. Python3NumPy——数组(1)之创建

    开篇 numpy库作为科学计算的基础库,其地位相当重要,它是对数组操作的基石.它的存在使得线性代数以及矩阵论等相关知识在计算机上的表达更加方便与简单,集中体现出了人想办法,计算机去工作. Python ...

  3. app 下载更新 file-downloader 文件下载库的简单介绍和使用

    app 下载更新 file-downloader 文件下载库的简单介绍和使用 今天介绍一个下载库:file-downloader 文件下载库 说明: * 本文内容来自原 file-downloader ...

  4. jQuery系列 第四章 jQuery框架的选择器

    第四章 jQuery框架的选择器 4.1 jQuery选择器说明 jQuery 最核心的组成部分就是选择器引擎.它完全继承了 CSS 的风格,可以对 DOM 元 素的标签名.属性名.状态等进行快速准确 ...

  5. 用js来实现那些数据结构06(队列)

    其实队列跟栈有很多相似的地方,包括其中的一些方法和使用方式,只是队列使用了与栈完全不同的原则,栈是后进先出原则,而队列是先进先出(First In First Out). 一.队列    队列是一种特 ...

  6. v-bind特性

    插值语法不能作用在 HTML 特性上,因此使用 v-bind 指令1.v-bind在一般特性上的使用:如id,src,disabled,checked,selected,name html: < ...

  7. [LeetCode] K Inverse Pairs Array K个翻转对数组

    Given two integers n and k, find how many different arrays consist of numbers from 1 to n such that ...

  8. js保留整数

    1.丢弃小数部分,保留整数部分parseInt(5/2) 2.向上取整,有小数就整数部分加1 Math.ceil(5/2) 3,四舍五入. Math.round(5/2) 4,向下取整 Math.fl ...

  9. [ZJOI 2013]丽洁体

    Description 题库链接 给出四个字符串 \(T,A,B,C\) ,问你至少在 \(T\) 串中删去几个单词能使得 \(T\) 串变为 \(A?B?C\) 的形式,其中 \(?\) 表示任意多 ...

  10. ●POJ 1741 Tree

    题链: http://poj.org/problem?id=1741题解: 树上点分治. 入门题,不多说了. 代码: #include<cstdio> #include<cstrin ...