
《数据结构与算法分析:C语言描述》部分代码
《数据结构与算法分析:C语言描述》部分代码
idjke
这个作者很懒,什么都没留下…
展开
-
图中的一些算法(邻接矩阵的方式)
使用邻接矩阵建立图图的建立及相关算法头文件所需函数定义图,边的结构建立图的方式两种遍历方式:广度优先搜索深度优先搜索最短路径问题无权图的单源最短路算法加权图的单源最短路算法:Dijkstra算法多源加权图最短路径:Floyd算法最小生成树问题Prim算法(针对稠密图)Kruskal算法头文件#include "Queue.cpp"//自己编写队列文件#include<stdio.h>#include<stdlib.h>#include<malloc.h>.原创 2020-09-07 21:14:24 · 284 阅读 · 0 评论 -
《数据结构与算法分析:C语言描述》习题3.19
3.19 编写一个程序计算后缀表达式的值在这里插入代码片原创 2020-08-20 15:49:47 · 414 阅读 · 0 评论 -
《数据结构与算法分析:C语言描述》习题3.18
3.18 (b)用C语言编写检测平衡符号的程序#include<stdio.h>#include<string.h>#include<malloc.h>#include<stdlib.h>/** 假定输入的字符串只包含各种括号* * 具体做法:* 遍历字符串,遇到左括号就存储到栈中,遇到右括号就将栈顶部的左括号弹出 如果左右括号匹配,则继续,直到完成遍历,如果不匹配,则返回false** 注意:如果碰到/* 则栈中仅存入'/'来表.原创 2020-08-18 18:17:05 · 462 阅读 · 0 评论 -
《数据结构与算法分析:C语言描述》习题4.10(实现二叉查找树)
4.10#include<stdio.h>#include<malloc.h>#include<stdlib.h>/* 二叉查找树 p80 1.假设二叉树中个元素互异 2.都是整数*/typedef struct BiTreeNode{ int data; struct BiTreeNode* pLeft; //左节点 struct BiTreeNode* pRight; //右节点}SearchTree,*PtrSearchTree;typ.原创 2020-08-10 16:43:11 · 296 阅读 · 0 评论 -
《数据结构与算法分析:C语言描述》习题3.6
3.6#include<stdio.h>#include<malloc.h>#include<stdlib.h>/* 进行书p45上两个多项式的加法(懒得用scanf输入) *//* 要求多项式必须有次数为0的项(没有则设为0) */typedef struct Node { //多项式中每一个部分的系数及指数 int coefficient; int exponent; struct Node* pNext;}PolyNode,*PtrPolyN.原创 2020-08-07 19:21:48 · 586 阅读 · 0 评论 -
《数据结构与算法分析:C语言描述》习题3.4~3.5
3.4(题目中两个链表均以升序排列)#include<stdio.h>#include<malloc.h>/* 用链表实现, 假定每一个输入链表都没有相同元素 */typedef struct node{ int data; struct node* pNext;}Node, * PtrNode;PtrNode MakeList(void); //创建链表,返回头节点void ShowList(PtrNode pHead); //打印链表中的数据Ptr.原创 2020-07-31 18:56:12 · 281 阅读 · 0 评论 -
《数据结构与算法分析:C语言描述》习题3.2~3.3
3.2 (题目中两个链表均以升序排列)#include<stdio.h>#include<malloc.h> /*假设输入都合法*/typedef struct node{ int data; struct node* pNext;}Node, * PtrNode;PtrNode MakeList(void); //创建链表void PrintLots(PtrNode L, PtrNode P);int main(void){ .原创 2020-07-30 17:49:18 · 497 阅读 · 0 评论 -
《数据结构与算法分析:C语言描述》习题2.16
#include<stdio.h>int Pow(int x, int n);//求x^nint main(void){ int x = 15; int n = 2; printf("%d\n", Pow(x, n)); return 0;}int Pow(int x, int n){ if (n == 0) return 1; int temp = x; while (n != 1) { if (n % 2 == 0) { temp =原创 2020-07-25 17:02:44 · 291 阅读 · 0 评论 -
《数据结构与算法分析:C语言描述》习题2.14
#include<stdio.h>#include<math.h>#include<malloc.h>void Erastothenes(int N);//寻找小于N的素数,该方法称为Erastothenes筛int main(void){ int N = 100; Erastothenes(N); return 0;}void Erastothenes(int N){ int* arr = (int*)malloc(sizeof(int)原创 2020-07-25 12:18:41 · 258 阅读 · 0 评论 -
《数据结构与算法分析:C语言描述》习题2.13
#include<stdio.h>#include<math.h>bool isPrime(int N);//判断N是否为素数int main(void){ int N = 15; if (isPrime(N)) printf("N=%d 是素数\n", N); else printf("N=%d 不是素数\n", N); return 0;}bool isPrime(int N){ for (int i = 2; i < sqrt(N原创 2020-07-25 11:32:48 · 174 阅读 · 0 评论 -
《数据结构与算法分析:C语言描述》习题2.12
a.求数列{An}\{A_n\}{An}的最小子序列和相当于求{−An}\{-A_n\}{−An}的最大子序列和。本题采用书中2.4.3节和算法3类似的算法。C语言代码如下:#include<stdio.h>#include<stdlib.h>int MinSubSum(int* arr, int left, int right);//求数组的最小连续子列的和int Min3(int a, int b, int c);//求这三者最小值int main(void.原创 2020-07-24 20:04:45 · 314 阅读 · 0 评论 -
《数据结构与算法分析:C语言描述》习题2.7
算法1 C语言代码:int* CreateArr_1(int N)//算法1{ int i, j, temp, count; int* pA = (int*)malloc(sizeof(int) * N); pA[0]= RandInt(0, N - 1); for (i = 1; i < N; i++) { count = 0; //用来判断A[O]到A[i-1]中是否有和temp相同的元素,count=0表示有和temp相同的元素 while (0 == count)/.原创 2020-07-23 17:07:55 · 372 阅读 · 0 评论