![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法与数据结构
文章平均质量分 73
liurry
一名在校大学生
展开
-
约瑟夫环问题(顺序表)——C++实现
#include#include#define MAXSIZE 100//人数上限using namespace std;typedef int DataType;typedef struct{ DataType data[MAXSIZE];//存放编号的数组 int length; //人数}SeqList,* PSeqList;int main(){ /*函数声明*/原创 2015-10-12 20:31:32 · 5583 阅读 · 0 评论 -
货币兑付
#include#define N 4using namespace std;int main(){ int s = 0, n,A[N] = { 25, 10, 5, 1 }; int * p=new int[N]; cout<<"输入所需支付的货币钱数n为:"; cin>>n; for(int i=0;i<N;i++){ p[i]=0; while((s+=A[i])原创 2015-10-13 17:32:22 · 556 阅读 · 0 评论 -
多段图问题(图的邻接表)
/**********************************//* 多段图问题 *//*求源点到汇点的最小花费及最短路径*//**********************************/#include#include#include#define MAX 100 /*最大顶点数为100*/using namespace原创 2015-11-12 22:12:27 · 1101 阅读 · 1 评论 -
农夫过河问题(图的邻接矩阵)
/********************************************************************************农夫过河问题(图的邻接矩阵存储,深度优先遍历): **一个农夫带着一只羊、一只狼、和一颗白菜过河(左岸->右岸); **河边只有一条船,由于船太小,只能装下农夫和他的一样东西; **原创 2015-11-12 22:11:47 · 2851 阅读 · 0 评论 -
分治法排序——C++实现
#include#include"stdlib.h"#define random(x) (rand()%x)using namespace std;int count1=0,count2=0;int comp(int a,int b){ count1++; if(a<=b) return 1; else return 0;}void swap(int a,int b){原创 2015-10-12 21:15:21 · 347 阅读 · 0 评论 -
主要的排序算法——Java实现
package cn.leilei.algorithm;public class Sort { /** * 内部排序算法 * 插入排序类:直接插入排序,希尔排序 * 选择排序类:选择排序,堆排序 * 交换排序类:冒泡排序,快速排序 * 归并排序 */ /** * 交换数组中的两个元素 * 方法名:swap * 创建人:潭州学院-liuch原创 2015-10-12 21:02:51 · 266 阅读 · 0 评论 -
单链表的逆置
#include#includeusing namespace std;typedef int DataType;/*定义链表数据结构*/typedef struct node{ DataType data; struct node * next;}LNode,* LinkList;int main(){ LinkList Tail_Create_LinkList();原创 2015-10-12 20:34:06 · 390 阅读 · 0 评论 -
单链表的基本操作——C++实现
#include#includeusing namespace std;typedef int DataType;/*定义链表数据结构*/typedef struct node{ DataType data; struct node * next;}LNode,* LinkList;int main(){ /*函数声明*/ LinkList Tail_Create_Li原创 2015-10-12 20:32:34 · 709 阅读 · 0 评论 -
哈密尔顿回路问题
/*******************************************************//* 哈密尔顿回路问题 *//*从一个顶点出发,经过每个顶点恰好一次,然后回到出发点 *//*******************************************************/#原创 2015-10-13 17:36:37 · 2029 阅读 · 0 评论 -
单源最短路径(图的邻接矩阵)
/********************************************************************************* 单源最短路径问题(图的邻接矩阵) **某一地区的一个公路网,给定了该网内的n个城市以及这些城市之间的相通公路的距离,能**否找到城市A到城市B之间的一条距离最近的通路呢? **将城市用顶点表原创 2015-11-12 22:13:12 · 704 阅读 · 0 评论 -
图的m着色问题
/*******************************************************//* 图的m着色问题 *//*给定无向图G=(V,E),用m中颜色为图中每个顶点着色,要求 每个顶点着一种颜色,并使相邻两个顶点之间具有不同的颜色*//************************原创 2015-10-13 17:37:15 · 343 阅读 · 0 评论 -
n皇后问题
/**********************************************//* n皇后问题 *//*自顶向下,路径上数值和最大,输出最大值及路径*//**********************************************/#includeusing namespace std;原创 2015-10-13 17:35:59 · 348 阅读 · 0 评论 -
图(邻接表)的深度、广度优先遍历
/******************************************************************************** ** 图(邻接表存储)的深度优先和广度优先 ** ************************************原创 2015-11-12 22:09:56 · 848 阅读 · 2 评论 -
0 1背包问题
/***************************************//* 0/1背包问题(物体不可分割) *//*求装入背包的物体及其总价值 *//***************************************/#include#include#define N 20 //最多物体个数#define M 1原创 2015-10-13 17:35:27 · 265 阅读 · 0 评论 -
最长公共子序列问题
/**********************************//* 最长公共子序列 *//*求A、B两字符序列的最长公共子序列*//**********************************/#include#define N 50 //最大A字符序列长度#define M 50 //最大B字符序列长度using namesp原创 2015-10-13 17:34:48 · 272 阅读 · 0 评论 -
多段图问题
/**********************************//* 多段图问题 *//*求源点到汇点的最小花费及最短路径*//**********************************/#include#include#include#define MAX 100 /*最大顶点数为100*/using namespace原创 2015-10-13 17:33:38 · 732 阅读 · 2 评论 -
背包问题(物体不可分割)
/***************************************************************************** 0/1背包问题(物体不可分割) 问题重述:对于给定的载重量为M的背包,以及n个重量为wi、价值为pi的物体,1<=i<=n, 要求用动态规划法求把物体装满背包,且使背包内的物体价值最大的解。/*********原创 2015-10-13 17:33:03 · 995 阅读 · 0 评论 -
图(邻接矩阵)的深度、广度优先遍历
/******************************************************************************** ** 图(邻接矩阵存储)的深度优先和广度优先 ** ***********************************原创 2015-11-12 22:10:59 · 653 阅读 · 0 评论 -
选择算法
#include#include"stdlib.h"#define random(x) (rand()%x)using namespace std;int count2=0;void swap(int a,int b){ int t; t=a;a=b;b=t; count2++;}void cjsz(int aa[],int n){ for(int i=0;i<n;i++原创 2015-10-12 21:53:56 · 246 阅读 · 0 评论 -
二叉树-递归遍历(先、中、后)
#include#include#include#define MAXSIZE 20 //最多结点个数using namespace std;/*二叉链表*/typedef struct bnode{ char data; struct bnode *lchild,*rchild;}Bnode,* BTree;BTree CreateBinTree(void); //原创 2015-10-12 20:43:20 · 284 阅读 · 0 评论 -
残缺棋盘
#include#includeusing namespace std;int tile=0,* (* B);void tileboard(int tr,int tc,int dr,int dc,int size){ int t,s; if(size==1) return; t=++tile; s=size/2; if((dr<tr+s)&&(dc<tc+s)) tile原创 2015-10-12 21:55:39 · 405 阅读 · 0 评论 -
数制转换问题(顺序栈)
#include#includeusing namespace std;#define MAXSIZE 50typedef int DataType;typedef struct{ DataType data[MAXSIZE]; int top;}SeqStack,* PSeqStack;int main(){ //函数声明 PSeqStack Init_SeqStack(原创 2015-10-12 20:36:39 · 1122 阅读 · 0 评论 -
背包问题(物体可分割)
/******************************************/ /* 贪心法求解背包问题(物体可分割) */ /******************************************/#include#define N 7using namespace std;typedef struct{ float p; // 物体的原创 2015-10-12 21:59:01 · 899 阅读 · 0 评论 -
单链表求集合交并
#include#includeusing namespace std;typedef int DataType;/*定义链表数据结构*/typedef struct node{ DataType data; struct node * next;}LNode,* LinkList;int main(){ /*函数声明*/ LinkList Tail_Create_Li原创 2015-10-12 20:34:43 · 876 阅读 · 0 评论 -
顺序表的基本操作——C++实现
目前是大四学生,在即将毕业照工作之际,想把数据结构和算法的基础好好学习,巩固下。用的学习教材是,秦锋主编的《数据结构(C语言版)》。以下就是我的顺序表实现代码:#include#include#define MAXSIZE 100//顺序表长度上限using namespace std;typedef int DataType;typedef struct{ DataTy原创 2015-09-06 16:12:49 · 667 阅读 · 0 评论 -
二叉树-层序遍历
#include#include#include#define MAXSIZE 20 //最多结点个数using namespace std;/*二叉链表*/typedef struct bnode{ char data; struct bnode *lchild,*rchild;}Bnode,* BTree;/*循环队列*/typedef BTree DataTy原创 2015-10-12 20:44:50 · 245 阅读 · 0 评论 -
链队
#include#include#define MAXSIZE 50using namespace std;typedef int DataType;typedef struct node{//数据节点 DataType data; struct node * next;}Qnode,* PQNode;typedef struct{ //头尾指针 PQNode front原创 2015-10-12 20:42:07 · 321 阅读 · 0 评论 -
单链表的复制——C++实现
#include#includeusing namespace std;typedef int DataType;/*定义链表数据结构*/typedef struct node{ DataType data; struct node * next;}LNode,* LinkList;int main(){ /*函数声明*/ LinkList Tail_Create_Li原创 2015-10-12 20:33:25 · 4311 阅读 · 0 评论 -
二叉树-非递归遍历(先、中、后)
#include#include#include#define MAXSIZE 20 //最多结点个数using namespace std;/*二叉链表*/typedef struct bnode{ char data; struct bnode *lchild,*rchild;}Bnode,* BTree;/*顺序栈*/typedef BTree DataTyp原创 2015-10-12 20:44:11 · 346 阅读 · 0 评论 -
迷宫问题(递归)
#include#include#define k 4 //试探方向个数#define m 6 //迷宫的实际行#define n 8 //迷宫的实际列using namespace std;//试探方向typedef struct{ int x,y;}item;int main(){ int path(int maze[m+2][n+2],item move[],原创 2015-10-12 20:38:26 · 446 阅读 · 0 评论 -
迷宫问题(顺序栈)
#include#include#define MAXSIZE 50#define k 4 //四个方向#define m 6 //迷宫的实际行#define n 8 //迷宫的实际列using namespace std;//试探方向typedef struct{ int x,y;}item;//栈的数据类型typedef struct{ //横纵坐标及方向原创 2015-10-12 20:37:21 · 785 阅读 · 0 评论 -
顺序栈——C++实现
#include#include#define MAXSIZE 50using namespace std;typedef int DataType;typedef struct{ DataType data[MAXSIZE]; int top;}SeqStack,* PSeqStack;int main(){ //函数声明 PSeqStack Init_SeqStack原创 2015-10-12 20:35:57 · 316 阅读 · 0 评论 -
顺序表求集合交并——C++实现
#include#include#define MAXSIZE 100//顺序表长度上限using namespace std;typedef int DataType;typedef struct{ DataType data[MAXSIZE];//顺序表存储结构 int length;//顺序表长度}SeqList,* PSeqList;int main(){ /*函数原创 2015-10-12 20:30:25 · 1954 阅读 · 1 评论 -
循环队列(顺序队列)
#include#include#define MAXSIZE 50using namespace std;typedef int DataType;typedef struct{ DataType data[MAXSIZE]; int front,rear; //队头和队尾指针}SeqQueue,* PSeqQueue;int main(){ /*函数声明*/原创 2015-10-12 20:40:24 · 352 阅读 · 0 评论 -
后缀表达式求值(顺序栈)
#include#include#define MAXSIZE 50using namespace std;typedef int DataType;typedef struct{ DataType data[MAXSIZE]; int top;}SeqStack,* PSeqStack;int main(){ //函数声明 PSeqStack Init_SeqStack原创 2015-10-12 20:39:34 · 1165 阅读 · 0 评论 -
二叉树-遍历
#include#include#include#define MAXSIZE 20 //最多结点个数using namespace std;/*二叉链表*/typedef struct bnode{ char data; struct bnode *lchild,*rchild;}Bnode,* BTree;/*顺序栈*/typedef BTree DataTyp原创 2015-10-12 20:45:32 · 302 阅读 · 0 评论 -
哈夫曼树——C++实现
#include using namespace std; #define MAXBIT 10#define MAXVALUE 10000#define MAXLEAF 100#define MAXNODE MAXLEAF*2-1 //定义哈夫曼树编码类型typedef struct{ char bit[MAXBIT]; //存放叶子结点字符编码过后的二进制编码 int原创 2015-10-12 20:46:25 · 531 阅读 · 0 评论 -
数塔问题
/************************************************************************ 数塔问题 自顶向下,路径上数值和最大,输出最大值及路径问题重述:对于给定的数塔,要求从顶部出发,找出一条走到底层的路径, 使路径上的数值和最大。************原创 2015-10-13 17:34:11 · 774 阅读 · 0 评论