![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C++
ThirteenL
这个作者很懒,什么都没留下…
展开
-
二叉树带权路径长度WPL
二叉树的带权路径长度的公式如下:WPL = 叶子节点的权重*该叶子节点的权重#include <iostream>using namespace std;typedef struct node { int weight; struct node *left; struct node *right;} TNode;TNode *CreateTree(TNode *&t);int WPL(TNode *t, int d);int wpl =原创 2021-12-17 00:19:43 · 2692 阅读 · 0 评论 -
插入排序之希尔排序
希尔排序是直接插入排序的改良版,因为直接插入排序在数组基本有序的时候(或则说每个值都快要接近正确位置时),排序效率最高,希尔排序就是为了通过分组的方式,使得待排序数组基本有序。当希尔排序步长为1时就是直接插入排序了。#include <iostream>using namespace std;void ShellSort(int arr[], int n);int main() { int arr[] = {25, 6, 23, 52, 1, 3, 5, 9, 6, 112原创 2021-12-12 22:12:05 · 532 阅读 · 0 评论 -
插入排序之直接插入排序
含二分查找的插入排序原创 2021-12-09 22:01:58 · 127 阅读 · 0 评论 -
数组负值放前面正值放在后面
#include <iostream>using namespace std;void Resort(int R[],int n);int main() { int R[] = {-1,2,2,-3,6,-6,-4}; Resort(R,7); for (int i : R) { cout<<i<<endl; } return 0;}void Resort(int R[],int n){ i原创 2021-12-09 11:36:13 · 340 阅读 · 0 评论 -
统计二叉树的叶子节点个数
#include <iostream>#include <queue>using namespace std;typedef struct node { char data; struct node *lchild; struct node *rchild;} TNode;TNode *CreateTree(TNode *&t);int Count(TNode *t); //统计t的叶子节点个数,非递归int R_Count(TN原创 2021-12-08 23:14:25 · 1275 阅读 · 0 评论 -
交换排序之冒泡排序
冒泡排序的思路是通过比较邻近两个元素的值的大小,然后判断是否进行交换,在冒泡排序时每一次都会有一个元素到达应该到的位置。#include <iostream>using namespace std;void swap(int &a, int &b);void BSort(int arr[], int num);int main() { int num = 6; int arr[] = {19, 98, 1, 12, 5, 1}; BSor原创 2021-12-06 22:56:16 · 67 阅读 · 0 评论 -
交换排序之快速排序
快速排序我们需要选择某一个数作为标志(一般选择第一个数),然后将数据以标志为界限划分成两块,左边的块全部小于标志,右边的块全部大于标志,接着我们采取递归的方式处理左右两块,直到划分出来的块只有一个元素时,作为递归的退出条件。#include <iostream>using namespace std;void swap(int &a, int &b);void QSort(int arr[], int low, int high);int Partition(int原创 2021-12-06 22:29:47 · 883 阅读 · 0 评论 -
广度优先遍历
广度优先遍历输入顶点数据输入边的信息广度优先遍历结果如下#include <iostream>#include <queue>#define MaxSize 10using namespace std;//边typedef struct arc_node { int adj_vex;//边对应节点在表中间的位置 struct arc_node *next_arc;//下一条边} ArcNode;//顶点typedef struct原创 2021-12-04 17:09:21 · 123 阅读 · 0 评论 -
线索二叉树(先序)
#include <iostream>using namespace std;typedef struct ThBTNode { char data; ThBTNode *l_child; ThBTNode *r_child; int l_tag, r_tag; //l_tag=1表示指向前驱,l_tag=0表示指向左孩子 //r_tag=1表示指向后继,r_tag=0表示指向右孩子} ThBTNode;ThBTNode *pre =原创 2021-11-28 21:25:28 · 476 阅读 · 0 评论 -
邻接表创建有向图
使用邻接表创建有向图,可以使用数组+链表的方式创建#include <iostream>using namespace std;//采用邻接表存储节点#define MaxSize 10// 定义边typedef struct arc_node { int adj_vex; //该边所指向节点的位置 struct arc_node *next_arc;} ArcNode;//定义顶点typedef struct vnode { char dat原创 2021-11-11 17:36:00 · 5288 阅读 · 3 评论 -
循环队列出队与入队
循环队列的入队与出队#include <iostream>#define MaxSize 10using namespace std;typedef struct Node { int data[MaxSize]; int front, rear; //队首,队尾指针} SQueue;SQueue *init_queue();int En_queue(SQueue &qu, int x);int De_queue(SQueue &qu,原创 2021-11-07 16:51:46 · 3101 阅读 · 0 评论 -
二叉树双序遍历
所谓二叉树的双序遍历就是,对于二叉树的每个节点来说,先访问该节点,再按照这种方式访问左子树,再访问该节点,再按照双序遍历访问右子树。该方法其实是对前序遍历进行了改变,多增加了一次访问节点函数的调用。代码如下:#include <iostream>using namespace std;typedef struct BTNode { char data; BTNode *l_child; BTNode *r_child;} BTNode;void Dou原创 2021-11-05 23:41:34 · 3206 阅读 · 3 评论 -
删除含有头结点的单链表中的最小值的结点
删除有头节点的单链表中的最小值的结点#include <iostream>using namespace std;typedef struct node { int data; struct node *next;} LNode;void Del_minNode(LNode *L);LNode *CreateLink(const int data[], int n);void PrtLink(LNode *L);int main() { int原创 2021-10-30 15:34:38 · 352 阅读 · 0 评论 -
C++按照空格分割字符串
C /A/B/1 1024C /A/B/2 1024C /A/B/1/3 1024C /A 1024R /A/B/1/3Q / 0 1500C /A/B/1 100Q / 0 1500R /A/BQ / 0 1当我们需要处理上述数据时,其中有空格作为标志进行分割我们可以采取C++中的一个处理string的标准库sstream。操作方法如下:string line, word;vector<string> Str;//创建一个存储string类型的vector;get原创 2021-03-28 14:38:13 · 10111 阅读 · 0 评论