- 博客(8)
- 收藏
- 关注
原创 快速排序
快速排序较冒泡排序而言,递归与两个for循环相比,降低了时间复杂度,速度也更快,是有效常用的一种排序方法。#include #include #define N 10void fast_sort(int a[],int beg,int end){ int l=beg,r=end; int t=a[beg]; if(beg<end) {
2015-09-20 16:26:46 198
原创 二叉堆
二叉堆是一种富有特色的数据结构,可用数组简便实现。有一些规律,eg:L_child=parent * 2 , R_child=parent * 2 + 1; #include #define N 100int heap[N],size=0;void push(int x){ int i=size++; while(i>0) { int j
2015-09-20 15:41:56 232
原创 全排列
#include char pre[100];char used[300];void permut(char a[],int pos,int n){ int i; if(pos==n) { printf("%s\n",pre); return ; } for(i=0;i<n;i++) { if(used[a[i]]==1) { pre[pos]=a[i];
2015-09-20 15:10:49 205
原创 二叉树的宽度和深度
#include #include int main(){ int i,n; int son[20][2]; int depth[20]={0}; scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%d%d",&son[i][1],&son[i][2]); } if(son[i
2015-09-20 14:35:52 223
原创 搜索树
#include #include struct node{ int val; struct node *lch; struct node *rch;};struct node *insert(struct node *p,int x) //插入,也是建树{ struct node *q; if(p==NULL) { q=(no
2015-08-12 20:18:30 208
原创 快速幂。素数筛选。辗转相除。
快速幂(位运算实现)时间复杂度由O(n)变为O(logn) #include int main(){ __int64 x,y; __int64 sum=1; scanf("%I64d%I64d",&x,&y); for(;y>0;y>>=1) { if(y&1==1) { sum*=x; } x*=x; } printf(
2015-08-12 19:53:49 265
原创 栈的简单操作
栈,其核心思想为先进后出。函数调用是其最重要的应用,其它应用还有输入,逆向输出、语法检查:括号匹配、数制转换、二叉树的遍历、表达式求值、迷宫(dfs)等。 基本操作的代码如下: #include #include #define SIZE 100typedef struct{ int data[SIZE]; int top;}stack,*
2015-08-12 17:38:51 259
原创 链表(单向)
二、算法1.算法的设计依赖于数据的逻辑结构,而算法的实现则取决于特定的物理结构。2.算法是对特定问题求解步骤的一种描述,是指令的有限序列。五大特性为:有穷、确定、可行、有输入、有输出。 三、线性表:1.顺序表 2.链表链表,较数组而言空间利用率上占优势,可以动态灵活地分配内存空间,但是不能随机读取。其基本操作为创建,插入,删除,查找,排序等,代码如下:
2015-08-12 17:29:39 241
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人