随笔分类 -  非数值算法

摘要:二半夜的有点失眠,来个睡眠排序 -_-|| 阅读全文
posted @ 2019-12-15 02:11 Dsp Tian 阅读(563) 评论(0) 推荐(0) 编辑
摘要:好久没更新过博客了,先转载一篇文章吧。源地址:http://www.cnblogs.com/LBSer/p/3310455.html引子 机机是个好动又好学的孩子,平日里就喜欢拿着手机地图点点按按来查询一些好玩的东西。某一天机机到北海公园游玩,肚肚饿了,于是乎打开手机地图,搜索北海公园附近的餐馆,... 阅读全文
posted @ 2015-09-16 10:07 Dsp Tian 阅读(1152) 评论(0) 推荐(0) 编辑
摘要:还是编程珠玑上的东西,作者对最初的算法稍微优化了一下。#include <iostream>#include <algorithm>#define N 10using namespace std;int binary_search(int *x,int n,int t) //x为要查找的数组,n为数组的大小,t为要找的值,找到则返回值的位置,否则返回-1{ int l=-1; //数组下界 int u=n; //数组上界 int p; //查找的值在数组中的位置 int m; //... 阅读全文
posted @ 2012-11-27 20:54 Dsp Tian 阅读(612) 评论(0) 推荐(0) 编辑
摘要:好久没看书了,随便拿来《编程珠玑》翻到第8章,介绍了一个叫求数组中最大子数组的算法,是线性的时间复杂度。 问题描述是具有n个浮点数的向量x,求向量中任何连续子向量的最大和。#include <iostream>using namespace std;int main(){ int x[10]={31,-41,59,26,-53,58,97,-93,-23,84}; int maxsofar=0; int maxendinghere=0; for (int i=0;i<10;i++) { maxendinghere=max(maxendinghe... 阅读全文
posted @ 2012-11-27 19:48 Dsp Tian 阅读(544) 评论(1) 推荐(0) 编辑
摘要:#include <iostream>#include <stdlib.h>using namespace std;typedef struct tree{ int data; struct tree *left; struct tree *right; struct tree *prior;}node;void preorder_tree(node *head){ if (head==NULL) return; cout<<head->data<<""; preorder_tree(head->left); pr 阅读全文
posted @ 2012-03-05 20:15 Dsp Tian 阅读(575) 评论(0) 推荐(0) 编辑
摘要:#include <iostream>#include <time.h>#include <stdlib.h>using namespace std;int random(int a,int b){ srand(NULL); return rand()%(b-a)+a;}void exchange(int &a,int &b){ int temp; temp=a; a=b; b=temp;}int partition(int *a,int p,int r){ int x=a[r]; int i=p-1; for (int j=p;j<r 阅读全文
posted @ 2012-02-20 14:07 Dsp Tian 阅读(644) 评论(0) 推荐(0) 编辑
摘要://元素只能为正整数#include <iostream>using namespace std;int Max(int *a,int length){ int temp=-1000; for (int i=0;i<length;i++) if (temp<a[i]) temp=a[i]; return temp;}void counting_sort(int *a,int *b,int k,int length){ int *c; c=(int*)malloc(sizeof(int)*(k+1)); for (int i... 阅读全文
posted @ 2012-02-19 14:03 Dsp Tian 阅读(452) 评论(0) 推荐(0) 编辑
摘要:#include <iostream>#include <time.h>#include <stdlib.h>using namespace std;int random(int a,int b){ srand(NULL); return rand()%(b-a)+a;}void exchange(int &a,int &b){ int temp; temp=a; a=b; b=temp;}int partition(int *a,int p,int r){ int x=a[r]; int i=p-1; for (int j=p;j<r 阅读全文
posted @ 2012-02-18 21:31 Dsp Tian 阅读(579) 评论(0) 推荐(0) 编辑
摘要:#include <iostream>using namespace std;void exchange(int &a,int &b){ int temp; temp=a; a=b; b=temp;}int partition(int *a,int p,int r){ int x=a[r]; int i=p-1; for (int j=p;j<r;j++) { if (a[j]<=x) { i=i+1; exchange(a[i],a[j]); } } ... 阅读全文
posted @ 2012-02-18 21:14 Dsp Tian 阅读(599) 评论(0) 推荐(0) 编辑
摘要:#include <iostream>using namespace std;int parent(int i){ return i/2;}int left(int i){ return 2*i;}int right(int i){ return 2*i+1;}void exchange(int &a,int &b){ int temp; temp=a; a=b; b=temp;}//但就算法来看,heap_size(堆的大小)设为全局变量也许会好一些void max_heapify(int *a,int i,int heap_size){ in... 阅读全文
posted @ 2012-02-17 21:46 Dsp Tian 阅读(446) 评论(0) 推荐(0) 编辑
摘要:#include <iostream>#include <time.h>#include <stdlib.h>using namespace std;int random(int a,int b){ srand(NULL); return rand()%(b-a)+a;}void exchange(int &a,int &b){ int temp; temp=a; a=b; b=temp;}int main(){ int a[]={1,2,3,4,5,6,7,8,9,10,11,12,13,14}; int length=sizeof(a)/ 阅读全文
posted @ 2012-02-17 19:00 Dsp Tian 阅读(551) 评论(0) 推荐(0) 编辑
摘要:#include <iostream>using namespace std;int parent(int i){ return i/2;}int left(int i){ return 2*i;}int right(int i){ return 2*i+1;}void exchange(int &a,int &b){ int temp; temp=a; a=b; b=temp;}void max_heapify(int *a,int i,int heap_size){ int l=left(i); int r=right(i); i... 阅读全文
posted @ 2012-02-17 18:59 Dsp Tian 阅读(455) 评论(0) 推荐(0) 编辑
摘要:#include <iostream>#include <stdlib.h>#include <time.h>using namespace std;#define NUM 30 //区间个数typedef struct { int min; //区间中最小值 int max; //区间中最大值 int diff; //区间的大小}extent;int Max(int a,int b){ if (a>=b) { return a... 阅读全文
posted @ 2012-02-03 15:17 Dsp Tian 阅读(1237) 评论(0) 推荐(0) 编辑
摘要:#include <iostream>using namespace std;int main(){ int a[9]={2,8,1,7,5,6,9,3,0}; int b[10]; int i; for (i=0;i<10;i++) { b[i]=-1; } for (i=0;i<9;i++) { b[a[i]]=a[i]; } for (i=0;i<10;i++) { if (b[i]==-1) { cout<<i<<endl; ... 阅读全文
posted @ 2012-02-03 13:33 Dsp Tian 阅读(514) 评论(0) 推荐(0) 编辑
摘要:bool isNumber(char s){ if (s >= 48 && s <= 57) return true; else return false;}bool isLetter(char s){ if (s >= 97 && s <= 122) return true; else return false;}//函数的作用是把如“-45+2*a-a^2-4*a^6+a^8”这样的字符串提取成这样:(-45,2,-1,0,0,0,-4,0,1),只提取系数,并根据指数安排起位置.//s为传入的字符串,resu... 阅读全文
posted @ 2011-12-04 14:42 Dsp Tian 阅读(2359) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示