- 博客(22)
- 收藏
- 关注
原创 统计字符串数组中所有单词出现的次数
#include <string.h> #include <stdlib.h> #include <iostream> #define N 20 #define MAX 10000 typedef struct { char word[N]; int count; }Word; int check(char ch) { if((ch>='A' && ch<='Z') || (ch>='a' && ch<
2020-11-15 17:37:50
749
原创 2020-11-14
#include <string.h> #include <stdlib.h> #include void swap(char *a,char *b) { char tmp=*a; *a=*b; *b=tmp; } void AllRange(char *str,int k,int m) { if(k==m) { printf("%s\n",str); } else { int i; for(i=k;i<=m;i++) { swap(&str[i],&str[
2020-11-14 17:26:17
147
原创 m个数的全排列
#include <string.h> #include <stdlib.h> #include <iostream> void swap(char *a,char *b) { char tmp=*a; *a=*b; *b=tmp; } void AllRange(char *str,int k,int m) { if(k==m) { static int s_i=1; printf("第%d个排列是%s\n",s_i++,str); } e
2020-11-14 16:26:23
339
原创 从n个数中抽取r个数的组合
#include <string.h> #include <stdlib.h> #include <iostream> void Combine(int n,int r,char a[],int b[],int R) { if(r==0) { int i=0; while(i<R) { printf("%c",a[b[i++]]); } printf("\n"); } else { int j; for(j=n;j&
2020-11-14 16:18:53
990
原创 2020-11-14
根据前缀表达式构建一个二叉树,其后序遍历就是它的后缀表达式 建树:从前缀表达式第一位往后建 #include <string.h> #include <stdlib.h> #include <iostream> typedef struct btnode { char data; struct btnode *lchild; struct btnode *rchild; }btnode; char A[]="*+ab/cd"; int n=strlen(A)
2020-11-14 14:11:59
120
原创 后缀表达式转前缀表达式
根据后缀表达式构建一个二叉树,其前序遍历就是它的前缀表达式 #include <string.h> #include <stdlib.h> #include <iostream> typedef struct btnode { char data; struct btnode *lchild; struct btnode *rchild; }btnode; char A[]="abc*+def/*/"; int n=strlen(A)-1; int ju
2020-11-13 18:21:12
1117
原创 中缀转前缀表达式
/中缀转前缀: 进栈元素:) + * - / 进栈规则: 从后往前扫中缀表达式 若栈顶元素比目前元素的优先级小,出栈,直到优先级相等;若栈顶元素与当前元素优先级相等,入栈; 若当前元素为’)‘入栈 若当前元素为’(’,出栈顶元素直到遇到’)‘位置,并且’('不表达 遇到操作数直接入栈/ #include <stdio.h> #include <math.h> #include <stdlib.h> #define N 10 void fun(char A[]) { c
2020-11-13 16:12:11
525
原创 前缀表达式的计算
/前缀表达式计算:中缀表达式为 a-(b+c)(d/e) 前缀表达式为 -a*+bc/de 中缀表达式储存在数组A[]中,创建栈stack[],从后往前扫,从数组中取出字符,遇到数字进栈,遇到运算符就出栈两次,进行计算,计算结果入栈 注意字符类型转换*/ #include <stdio.h> #include <math.h> #include <stdlib.h> #define N 100 int judge_char(char c) { switch(c) {
2020-11-13 16:06:31
3031
1
原创 计算中缀表达式、中缀转后缀表达式、中缀转前缀表达式一般思想
计算中缀表达式、中缀转后缀表达式、中缀转前缀表达式一般思想: 两个栈:临时存储stack[ ], 结果存储result[ ] stack进栈元素: 计算中缀表达式,中缀转后缀 :( + * - / 中缀转前缀:) + * - / stack进栈规则: 计算中缀表达式,中缀转后缀: 从前往后扫表达式 若当前元素为’(‘入栈 若当前元素为’)’,出栈顶元素直到遇到’(‘位置,并且’)'不表达 中缀转前缀: 从后往前扫表达式 若当前元素为’)‘入栈 , 若当前元素为’(’,出栈顶元素直到遇到’)‘位置,并且’('
2020-11-13 15:39:35
199
原创 中缀转后缀表达式
/中缀转后缀: 进栈元素:( + * - / 进栈规则: 若栈顶元素比自己的优先级小,出栈,直到优先级相等;若栈顶元素优先级相等,入栈; 若当前元素为’(‘入栈 ,若当前元素为’)’,出栈顶元素直到遇到’(‘位置,并且’)'不表达 遇到操作数直接表达/ #include <stdio.h> #include <math.h> #include <stdlib.h> #define N 10 void fun(char A[]) { char stack[N]; in
2020-11-13 15:03:34
117
原创 中缀表达式的计算
/*中缀表达式计算:中缀表达式为 (a+b)*c 中缀表达式储存在数组A[]中,创建栈stack1[]用来存放运算符,从数组中取出字符: 如果是’+’ ‘-’,栈顶元素出栈,直到栈空或者 ‘**’ ‘/’,再入栈 如果是 * ‘/’,如果栈顶是 * /,出栈直到栈空或者 * /,再入栈 如果是’(‘入栈 如果是’)'出栈直到遇到 ‘(’ 创建stack2[ ]用来存放数字 注意字符类型转换 */ #include <stdio.h> #include <math.h> #i
2020-11-12 18:43:58
1134
1
原创 后缀表达式计算
/后缀表达式计算:中缀表达式为 a-(b+c)(d/e) 后缀表达式为 abc+de/- 后缀表达式储存在数组A[]中,创建栈stack[],从数组中取出字符,遇到数字进栈,遇到运算符就出栈两次,进行计算,计算结果入栈 注意字符类型转换/ #include <stdio.h> #include <math.h> #include <stdlib.h> #define N 9 int judge_char(char c) { switch(c) { case
2020-11-12 17:40:42
478
原创 给定前序序列和中序序列唯一确定一棵二叉树
#include <stdio.h> #include <stdlib.h> #include <string.h> #define N 100 typedef struct btnode { char data; btnode *lchild; btnode *rchild; }btnode; btnode *create_tree(char pre_order[],char in_order[],int pre_l,int pre_r,int in_l,i
2020-11-11 15:57:03
393
原创 顺序存储数组构造二叉树
#include <stdio.h> #include <stdlib.h> #include <string.h> #define N 100 /*一棵具有n个节点的完全二叉树以顺序方式存储在数组A[]中,设计一个算法构造二叉树的二叉链式存储结构 构造函数,传入数组A,传入根节点bt,bt->data=i,bt->lchild->data=2*i+1,bt->rchild->data=2*i+2*/ typedef struct btno
2020-11-11 14:18:23
1090
1
原创 二叉树统计问题汇总
#include <stdio.h> #include <stdlib.h> #define N 100 /*二叉树非递归*/ typedef struct btnode { char data; btnode *lchild; btnode *rchild; }btnode; int i=0; int aa[]={55,10,7,-1,-1,22,-1,-1,66,-1,100,-1,-1}; char bt[]={'a','b','c','#','#','d','g
2020-11-11 13:46:46
160
原创 c语言二叉树的遍历——简单算法
#include <stdio.h> #include <stdlib.h> #define N 100 /*二叉树非递归*/ typedef struct btnode { char data; btnode *lchild; btnode *rchild; }btnode; int i=0; int aa[]={55,10,7,-1,-1,22,-1,-1,66,-1,100,-1,-1}; char a[]={'a','b','c','#','#','d','#'
2020-11-10 16:39:45
436
原创 c语言Dijkstra算法
#include <stdio.h> /Dijkstra算法:解决最短路径问题,从一个初始点v0出发,设置lowcost[]数组,记录初始点到每一个顶点的最短路径,设置path[]数组 记录初始点到每个点最短路径所经过的每一个点,设置visit[]数组,记录已经选入lowcost数组的点设置为 1 ,下次经过不再选中。 思想:选择初始点v,遍历每个点,若两个点之间存在路径,记录权值到lowcost数组,然后对每个点进行判断,每次挑选一个最小权值进入lowcost数组 并更新最小边/ #defin
2020-11-09 15:49:22
793
原创 c语言直接插入排序
/直接插入排序:对数组中未排好序的序列向排好序的序列进行插入,从排好序的序列最后一位向前找,直到找到比他小的元素插入到它后面 用一个暂时变量代表目标元素,每一个比它大的都往后移动一位 传入数组a[ ],大小 n/ #include <stdio.h> void insert_sort(int a[],int n) { int i,j,temp; for(i=1;i<n;++i) { temp=a[i]; for(j=i-1;j>=0;--j) { if(te
2020-11-06 16:21:22
156
原创 c语言冒泡排序
/*冒泡排序:目标数字,与前一个数字就行比较,如果前一个较大,则交换一下 从数组第一位向最后一位进行冒泡,每完成一次,最后一位减一 ,如果一次排序没有发生交换,则排序完成break 传入数组a[ ],大小 n */ #include <stdio.h> void pop_sort(int a[],int n) { int i,j,temp; int tag; for(i=n-1;i>=1;--i) { j=1;tag=0; while(j<=i) { if
2020-11-06 16:04:04
158
原创 c语言快速排序算法
/快速排序:每次选择一个基点,进行排序,基点左边都小于它,右边都大于它 传入数组,左边界,右边界/ #include <stdio.h> void quick_sort(int a[],int Left,int Right) { int L=Left,R=Right; int tag=a[L]; if(L>=R) return; else { while(L<R) { while(a[R]>=tag && L<R) R--;
2020-11-06 15:45:50
190
原创 简单选择排序
/简单选择排序:每次选出最小的一个,与数组首位发生交换,首位后移一位 传入数组a[ ],大小n/ #include <stdio.h> void quick_sort(int a[],int n) { int i,j; int min,tag,temp; for(i=0;i<n;++i) { min=a[i]; for(j=i+1;j<n;++j) { if(a[j]<min) { min=a[j]; tag=j; }
2020-11-06 15:03:28
99
原创 c语言堆排序
#include <stdio.h> int hipsort(int a[],int L,int R) { /从数组孩子节点选出最大的一个下标,与父节点比较,如果子节点大则,与父节点交换。 如果发生交换,则继续比较孩子节点与孩子节点的孩子节点的大小,传入要判断数组节点下标L,与判断边界R,当右孩子超出边界,判断停止 当前节点i=L,范围R,左孩子节点2i+1,右孩子节点2i+2,判断2i+1<=R*/ int i=L,j=2*i+1; int temp=a[i]; while(j&l
2020-11-06 14:32:24
559
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅