- 博客(38)
- 资源 (1)
- 收藏
- 关注
原创 单源最短路径(图的邻接矩阵)
/********************************************************************************* 单源最短路径问题(图的邻接矩阵) **某一地区的一个公路网,给定了该网内的n个城市以及这些城市之间的相通公路的距离,能**否找到城市A到城市B之间的一条距离最近的通路呢? **将城市用顶点表
2015-11-12 22:13:12
765
原创 多段图问题(图的邻接表)
/**********************************//* 多段图问题 *//*求源点到汇点的最小花费及最短路径*//**********************************/#include#include#include#define MAX 100 /*最大顶点数为100*/using namespace
2015-11-12 22:12:27
1194
1
原创 农夫过河问题(图的邻接矩阵)
/********************************************************************************农夫过河问题(图的邻接矩阵存储,深度优先遍历): **一个农夫带着一只羊、一只狼、和一颗白菜过河(左岸->右岸); **河边只有一条船,由于船太小,只能装下农夫和他的一样东西; **
2015-11-12 22:11:47
2910
原创 图(邻接矩阵)的深度、广度优先遍历
/******************************************************************************** ** 图(邻接矩阵存储)的深度优先和广度优先 ** ***********************************
2015-11-12 22:10:59
695
原创 图(邻接表)的深度、广度优先遍历
/******************************************************************************** ** 图(邻接表存储)的深度优先和广度优先 ** ************************************
2015-11-12 22:09:56
948
2
原创 图的m着色问题
/*******************************************************//* 图的m着色问题 *//*给定无向图G=(V,E),用m中颜色为图中每个顶点着色,要求 每个顶点着一种颜色,并使相邻两个顶点之间具有不同的颜色*//************************
2015-10-13 17:37:15
368
原创 哈密尔顿回路问题
/*******************************************************//* 哈密尔顿回路问题 *//*从一个顶点出发,经过每个顶点恰好一次,然后回到出发点 *//*******************************************************/#
2015-10-13 17:36:37
2068
原创 n皇后问题
/**********************************************//* n皇后问题 *//*自顶向下,路径上数值和最大,输出最大值及路径*//**********************************************/#includeusing namespace std;
2015-10-13 17:35:59
393
原创 0 1背包问题
/***************************************//* 0/1背包问题(物体不可分割) *//*求装入背包的物体及其总价值 *//***************************************/#include#include#define N 20 //最多物体个数#define M 1
2015-10-13 17:35:27
293
原创 最长公共子序列问题
/**********************************//* 最长公共子序列 *//*求A、B两字符序列的最长公共子序列*//**********************************/#include#define N 50 //最大A字符序列长度#define M 50 //最大B字符序列长度using namesp
2015-10-13 17:34:48
312
原创 数塔问题
/************************************************************************ 数塔问题 自顶向下,路径上数值和最大,输出最大值及路径问题重述:对于给定的数塔,要求从顶部出发,找出一条走到底层的路径, 使路径上的数值和最大。************
2015-10-13 17:34:11
812
原创 多段图问题
/**********************************//* 多段图问题 *//*求源点到汇点的最小花费及最短路径*//**********************************/#include#include#include#define MAX 100 /*最大顶点数为100*/using namespace
2015-10-13 17:33:38
818
1
原创 背包问题(物体不可分割)
/***************************************************************************** 0/1背包问题(物体不可分割) 问题重述:对于给定的载重量为M的背包,以及n个重量为wi、价值为pi的物体,1<=i<=n, 要求用动态规划法求把物体装满背包,且使背包内的物体价值最大的解。/*********
2015-10-13 17:33:03
1040
原创 货币兑付
#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
582
原创 背包问题(物体可分割)
/******************************************/ /* 贪心法求解背包问题(物体可分割) */ /******************************************/#include#define N 7using namespace std;typedef struct{ float p; // 物体的
2015-10-12 21:59:01
934
原创 残缺棋盘
#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
428
原创 选择算法
#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
296
原创 分治法排序——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
384
原创 主要的排序算法——Java实现
package cn.leilei.algorithm;public class Sort { /** * 内部排序算法 * 插入排序类:直接插入排序,希尔排序 * 选择排序类:选择排序,堆排序 * 交换排序类:冒泡排序,快速排序 * 归并排序 */ /** * 交换数组中的两个元素 * 方法名:swap * 创建人:潭州学院-liuch
2015-10-12 21:02:51
289
原创 哈夫曼树——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
572
原创 二叉树-遍历
#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
340
原创 二叉树-层序遍历
#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
264
原创 二叉树-非递归遍历(先、中、后)
#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
369
原创 二叉树-递归遍历(先、中、后)
#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
316
原创 链队
#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
342
原创 循环队列(顺序队列)
#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
372
原创 后缀表达式求值(顺序栈)
#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
1223
原创 迷宫问题(递归)
#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
472
原创 迷宫问题(顺序栈)
#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
821
原创 数制转换问题(顺序栈)
#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
1172
原创 顺序栈——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
334
原创 单链表求集合交并
#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
916
原创 单链表的逆置
#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
424
原创 单链表的复制——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
4426
原创 单链表的基本操作——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
764
原创 约瑟夫环问题(顺序表)——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
5687
原创 顺序表求集合交并——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
2023
1
原创 顺序表的基本操作——C++实现
目前是大四学生,在即将毕业照工作之际,想把数据结构和算法的基础好好学习,巩固下。用的学习教材是,秦锋主编的《数据结构(C语言版)》。以下就是我的顺序表实现代码:#include#include#define MAXSIZE 100//顺序表长度上限using namespace std;typedef int DataType;typedef struct{ DataTy
2015-09-06 16:12:49
706
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人