随笔分类 -  data structure

数据结构中的树相关编程题
摘要:数据结构中的树相关编程题 2017(3): 计算并输出树中每个叶子结点的data域值与所在的层数(递归) void fun(TNode *t,int h) //t为树结点指针,h为该结点深度 { if(t == NULL) return; //如果该结点为空,直接退出该函数 if(t->firstc 阅读全文

posted @ 2019-11-22 10:39 ewitt 阅读(693) 评论(0) 推荐(0)

递归求数组最小值; 递归求数组的平均值
摘要:递归求数组的平均值 #include <iostream.h> int a[10]={6,2,7,3}; float avg(int n)//n代表元素个数 { if(n==1) return a[0]; return (a[n-1]+avg(n-1)*(n-1))/n; } //一个递归调用(此处为avg(n-1))就相当于一个循环 void main() { int n; cin>>n; co 阅读全文

posted @ 2019-09-29 21:58 ewitt 阅读(1366) 评论(0) 推荐(0)

文档编辑(使用map标准库的C++)
只有注册用户登录后才能阅读该文。

posted @ 2018-12-26 09:01 ewitt 阅读(1) 评论(0) 推荐(0)

顺序表元素分块(左负右正中间零)
摘要:#include void partSort(int arr[],int l,int r) { int p=l,i=l,t,cnt=0; printf("\n负数调在前\n"); for(;i=p;i--) if(arr[i]==0) { t=arr[i];arr[i]=arr[p];arr[p]=t; ... 阅读全文

posted @ 2018-11-29 15:48 ewitt 阅读(177) 评论(0) 推荐(0)

二叉树的基本操作实现,包括二叉搜索树的判断
摘要:#include using namespace std; //定义节点 typedef struct node { struct node *lchild; struct node *rchild; int data; }BiTreeNode, *BiTree; //*BiTree的意思是给 struct node*起了个别名,叫BiTree,故BiTree为... 阅读全文

posted @ 2018-11-29 15:45 ewitt 阅读(215) 评论(0) 推荐(0)

修道士与野人问题(BFS广度搜索)
摘要:去掉调试代码: 阅读全文

posted @ 2017-06-10 09:02 ewitt 阅读(1610) 评论(0) 推荐(1)

Heap Sort
摘要:#include #define N 8 int a[]={0,39,21,40,92,29,11,32,9}; void Adjust(int i,int last) { int k=2*i; int t=a[i],tag=1; while(ka[k+1]) k++; if(t>a[k]) { a[i]=a[k]; i=k; k=2*i; ... 阅读全文

posted @ 2017-05-23 20:29 ewitt 阅读(135) 评论(0) 推荐(0)

Hash表
摘要:#include "iostream.h" #include "fstream.h" #include "string.h" #define MaxLen 13 #define Div 11//被除数 typedef struct node { char name[20]; int age; bool tag; }addrBook; addrBook *bk=n... 阅读全文

posted @ 2017-05-09 21:47 ewitt 阅读(140) 评论(0) 推荐(0)

hanoi(老汉诺塔问题新思维)
摘要:此解用于讲解原问题与子问题之间能建立合适的关系即可,无需要非要让n阶问题与n-1阶问题产生关系。 n阶问题与其子问题n-2阶问题如下图所示: 阅读全文

posted @ 2017-05-03 14:46 ewitt 阅读(232) 评论(0) 推荐(0)

prim算法
摘要:#include #include using namespace std; #define MAX 5 #define INF 32765 int AdjMtx[MAX][MAX]= {{INF ,1,INF,4,3}, {1,INF,2,INF,INF}, {INF,2,INF,2,3}, {4,INF,2,INF,1}, {3,INF,3,1,INF}}; int lowcost[... 阅读全文

posted @ 2017-04-27 21:57 ewitt 阅读(155) 评论(0) 推荐(0)

Kruscal algorithm
摘要:#include #include using namespace std; #define MAX 5 #define INF 32765 int graph[MAX][MAX]= {{INF ,1,INF,4,3}, {1,INF,2,INF,INF}, {INF,1,INF,2,3}, {4,INF,2,INF,1}, {3,INF,3,1,INF}}; typedef struct... 阅读全文

posted @ 2017-04-25 15:56 ewitt 阅读(170) 评论(0) 推荐(0)

递归程序设计思想(看图思考2小时)
摘要:递归程序设计思想: 1、原问题是如何由子问题解决的;(即原问题与子问题的递归关系) 2、子问题与原问题的解决方案是否一模一样。 阅读全文

posted @ 2017-04-06 21:28 ewitt 阅读(191) 评论(0) 推荐(0)

广义表的实现(法二)
摘要:#include #include using namespace std; enum elemTag {ATOM,LIST}; class GList; class GLnode { private: elemTag Tag; //标志是原子还是子表 0:原子 1:子表 union { char data; //原子结点值域 st... 阅读全文

posted @ 2017-03-30 21:40 ewitt 阅读(503) 评论(0) 推荐(0)

广义表的实现
摘要:/*--------------------------------------------------------------------- 广义表的存储结构 ---------------------------------------------------------------------*/ #include #include typedef char ElemTy... 阅读全文

posted @ 2017-03-30 21:37 ewitt 阅读(2665) 评论(0) 推荐(0)

将字符串中的星号去掉
摘要:#include "iostream.h" #include "string.h" void main() { char a[]="******ab**c*****d*efgh****k***"; int i=0,starCnt=0; while (a[i]=='*') i++; while (a[i]!='\0') { if(a[i]==... 阅读全文

posted @ 2017-03-26 19:12 ewitt 阅读(3024) 评论(0) 推荐(0)

多项式相加(顺序表)
摘要:#include typedef struct { int coef; int index; }datatype ; typedef struct { datatype *elem; int length; }SeqList; void BuildPoly(SeqList &s) { s.elem=new datatype[10]; s.len... 阅读全文

posted @ 2017-03-13 13:03 ewitt 阅读(1607) 评论(1) 推荐(0)

linklist template
摘要:#include typedef int ElemType; typedef struct LNode { ElemType data; struct LNode *next; }LNode; void CreateList(LNode *&L,int a[],int n) { LNode *p; L=new LNode; L->next=... 阅读全文

posted @ 2017-03-03 15:52 ewitt 阅读(217) 评论(0) 推荐(0)

seqlist template
摘要:1 #include 2 typedef int ElemType; 3 typedef struct{ 4 ElemType *elem; 5 int length; 6 }SeqList; 7 8 void InitSeq(SeqList &L,int n,ElemType a[]) 9 { int i=0; 10 L.elem=new ElemTy... 阅读全文

posted @ 2017-03-03 15:40 ewitt 阅读(284) 评论(0) 推荐(0)

导航