
数据结构
烈焰星辰
每天进步一点点
展开
-
顺序链表的基本操作
#include <stdio.h>#include <stdlib.h>#define maxsize 3#define addsize 2typedef int elemType;typedef struct{ elemType *List;//首地址 int length;//长度 int listSize;//分配的内存大小} sqList;//初始化顺序链表void initList(sqList *L){ L-原创 2021-12-14 14:29:44 · 125 阅读 · 0 评论 -
设顺序表va中的数据元素递增有序。试设计一个算法,将x插入到顺序表的适当位置上,以保持该表的有序性。
#define MaxSize 100#include<stdio.h>typedef int DataType;typedef struct { DataType list[MaxSize]; int size;}SeqList;void ListInitiate(SeqList* L)//初始化顺序表L{ L->size = 0;} //定义初始元素个数int ListLength(SeqList L) {//返回顺序表L的当前元素个数 return L.siz原创 2021-12-14 14:13:43 · 904 阅读 · 0 评论 -
链队基本操作
#include <stdio.h>#include <malloc.h>typedef char ElemType;typedef struct DataNode{ ElemType data; struct DataNode *next;} DataNode; //链队数据节点类型定义typedef struct{ DataNode *front; DataNode *rear;} LinkQuNode; //链队类型定义void Init原创 2021-12-13 21:49:51 · 96 阅读 · 0 评论 -
java中如何将字符串从任意进制转为十进制
算法刷题原创 2022-08-30 19:00:22 · 2523 阅读 · 0 评论 -
四大经典排序算法(C语言实现)
四大经典排序算法一、基数排序二、桶排序三、计数排序四、堆排序一、基数排序#ifndef sort__h#define sort__h#include <cstdio>#include <algorithm>#include <vector>#include <iostream>using namespace std;void print_array(int *arr, int n);// 打印数组int* sort_array(原创 2022-01-20 12:15:51 · 398 阅读 · 0 评论 -
判断给定的树是否为完全二叉树
#include<stdio.h>#include<stdlib.h>typedef char DataType; //声明数据类型struct BiTreeNode{ DataType data; BiTreeNode *leftChild; BiTreeNode *rightChild;};//初始化二叉树void initiateBiTree(BiTreeNode **root){ (*root) = (BiTreeNod原创 2021-12-13 16:50:42 · 68 阅读 · 0 评论 -
设一棵二叉树以二叉链表为存贮结构,设计一个算法将二叉树中所有结点的左,右子树相互交换
#include"stdio.h"#include"stdlib.h"typedef char DataType;typedef struct Node { DataType data; struct Node *leftChild; struct Node *rightChild;}BiTreeNode;void PrintData(DataType x){ printf("%c",x);}/*按先序序列建立一棵二叉树*/void CreatBiTree(BiTre原创 2021-12-13 15:21:34 · 4820 阅读 · 0 评论 -
编写计算二叉树最大宽度的算法二叉树采用二叉链表存储二叉树的最大宽度是指二叉树所有层中结点个数的最大值
#include <iostream>#include <cstring>using namespace std;int k=0;int m=0; typedef struct BiTNode{ char data; struct BiTNode *lchild,*rchild; }BiTNode,*BiTree; void CreateBiTree(BiTree &T){ char ch; cin>>ch; if(ch=='0')T原创 2021-12-13 15:10:12 · 1644 阅读 · 0 评论 -
编写计算整个二叉树高度的算法(二叉树的高度也叫二叉树的深度)。
#include"stdio.h"#include"stdlib.h"typedef char DataType;typedef struct Node { DataType data; struct Node *leftChild; struct Node *rightChild;}BiTreeNode;void PrintData(DataType x){ printf("%c",x);}/*按先序序列建立一棵二叉树*/void CreatBiTree(BiTre原创 2021-12-13 14:52:29 · 1026 阅读 · 0 评论 -
编写递归算法,在二叉树中求位于先序序列中第k个位置的结点的值
#include <stdio.h>#include <stdlib.h>#include <stdbool.h>typedef struct BiTNode{ char data; struct BiTNode *Lchild, *Rchild;}BiTNode,*BiTree;// 6_41bool Find_K(BiTree B1,int* i, int k){ if(B1 == NULL) return false;原创 2021-12-13 12:18:38 · 308 阅读 · 0 评论 -
二叉链表的创建
#include"stdio.h"#include"stdlib.h"typedef char DataType;typedef struct Node { DataType data; struct Node *leftChild; struct Node *rightChild;}BiTreeNode;void PrintData(DataType x){ printf("%c",x);}/*按先序序列建立一棵二叉树*/void CreatBiTree(BiTre原创 2021-12-12 01:51:48 · 2418 阅读 · 0 评论 -
设计一个算法,用深度优先遍历法对AOV网进行拓扑排序,检测其中是否存在环。
#include<cstdio>#include<algorithm>#include<queue> using namespace std; const int maxn = 1010; int vNum;vector<int> G[maxn];int inDegree[maxn] = {0};//记录每个点的入度 int inqNum = 0; bool topoSort(){ queue<int> Q; for(原创 2021-12-11 11:42:58 · 273 阅读 · 0 评论 -
深度优先遍历算法非递归实现(图用邻接矩阵存储)
# define INFINITY 1000# define MAX_VERTEX_NUM 20 //最大值# define OK 1#define MAX_VERTEX_NUM 20// 定义常量MAX_VERTEX_NUM为20#include<stdio.h>#include<stdlib.h> #include <iostream>#define MaxQueueSizea 100;typedef enum{DG,DN,UDG,UDN} Graph原创 2021-12-11 11:10:45 · 653 阅读 · 0 评论 -
设计一个算法,求出分别用邻接矩阵和邻接表表示的有向图中顶点的最大出度值
创建无向图代码更改int CreatUDN(MGraph &G){ int IncInfo,i,j,k,v1,v2,w; printf("Please input the number of G.vexnum (eg,G.vexnum=4):"); scanf("%d",&G.vexnum);//输入顶点数 G.vexnum printf("Please input the number of G.arcnum (eg,G.arcnum=4): "); scanf("%d",.原创 2021-12-10 00:01:08 · 1616 阅读 · 0 评论 -
设计一个算法,删除无向图的邻接矩阵中给定顶点。
图的结构定义# define INFINITY 1000# define MAX_VERTEX_NUM 20 //最大值# define OK 1#define MAX_VERTEX_NUM 20// 定义常量MAX_VERTEX_NUM为20#include<stdio.h>#include<stdlib.h> #include <iostream>#define MaxQueueSizea 100;typedef enum{DG,DN,UDG,U.原创 2021-12-09 23:46:51 · 688 阅读 · 0 评论 -
编写一个算法,求出邻接矩阵表示的无向图中序号为 numb 的顶点的度数。
头文件信息# define MAX_VERTEX_NUM 20 //最大值# define OK 1#define MAX_VERTEX_NUM 20// 定义常量MAX_VERTEX_NUM为20#include<stdio.h>#include<stdlib.h> #include <iostream>#define MaxQueueSizea 100;typedef enum { DG, DN, UDG, UDN } GraphKind;// {.原创 2021-12-06 21:10:50 · 644 阅读 · 0 评论