随笔分类 -  《数据结构与算法》

The beginning of Data structures and algorithms.
摘要:1 #include 2 #define N 6 3 int sum(int n, const arr[]);//求和函数声明declare 4 int main(void){ 5 int arr[N]; 6 int i; 7 int t_sum = 0; 8 9 for (i = 0; i < N;i++){//input int numb... 阅读全文
posted @ 2017-04-04 19:21 Micheal_you 阅读(321) 评论(0) 推荐(0)
摘要:问题背景:判断数字x是否在一个包含N个数字的列表中S。这里采用三种方法来改变主函数中参数值。分别为:返回值(return)、定义全局变量和指针方法 注意(*ptr_location)++ 一定有括号方式一:返回参数 return int 1 #include 2 //void search(int n, int x, const int arr[]); 3 int main(voi... 阅读全文
posted @ 2017-04-04 13:30 Micheal_you 阅读(159) 评论(0) 推荐(0)
摘要:【1】扑克牌洗牌算法: ********************************************* 函数名:void get_rand_number(int array[],int length) 功能:随机交换数组中位置,达到洗牌目的 备注:全局洗牌:value = rand()% 阅读全文
posted @ 2016-03-04 11:32 Micheal_you 阅读(1843) 评论(0) 推荐(0)
摘要:该知识,转自《编程之美》 问题中要求一个变量。注意原题问题的转化:建立一个逻辑的坐标系统(1~9来标记将帅的位置);要求用一个变量解法一:(出数学的方式,将变量转化为9进制数,)#include "stdafx.h"int _tmain(int argc, _TCHAR* argv[]){ i... 阅读全文
posted @ 2016-01-18 22:02 Micheal_you 阅读(476) 评论(0) 推荐(0)
摘要:基本思想:将第i个数插入前面的有序数组中。如此反复循环,直到全部排好序。/*****************************函数:插入排序功能:每一次,将一个数插入到,有序数组中的合适位置, 1.有序数,后移 2.插入合适位置 注意移动数组,不要被覆盖掉。利用temp。复杂... 阅读全文
posted @ 2016-01-08 15:51 Micheal_you 阅读(137) 评论(0) 推荐(0)
摘要:基本思想:从数组中选出最小的数,排在已经排好顺序的后面。如第一小,排在最前面,第二小,排在第二。。/****************************函数:选择排序功能:每一次,与第i位比较,将最小的排在最前面。复杂度:n*n作者:Micheal时间:2016-01-08***********... 阅读全文
posted @ 2016-01-08 14:43 Micheal_you 阅读(146) 评论(0) 推荐(0)
摘要:基本思想:在要排序数列中,比较相邻的两个数,将大数下沉,小数上浮。时间复杂度:n2实现代码:(c++) 1 /**************************** 2 函数:冒泡排序 3 注意细节:2个数,进行1次比较,n个数,进行n-1次比较;第二个for循环,实质是进行大数下沉的作用。 4 ... 阅读全文
posted @ 2016-01-08 14:39 Micheal_you 阅读(125) 评论(0) 推荐(0)
摘要:1 #include "stdafx.h" 2 #include "iostream" 3 #include "time.h" //用到time(null)函数,需要此头文件 4 5 using namespace std; 6 7 int a[100000]; 8... 阅读全文
posted @ 2016-01-08 14:34 Micheal_you 阅读(406) 评论(0) 推荐(0)