这个东西,从研究到写完,用了18小时.是我太笨了吗?不过还好,总算是写出来了.

收拾收拾,准备去那个城市考察一下.但愿带回真实的数据供我参考.

/*9-32(a)-12-29-21.48.c -- 第九章第三十二题*/

#include

#include

#include "new_adjacenty_list.h"

#include "rqueue.h"

#define SIZE (12)

int g_last_path = INFINITY ;

int main (void) ;

void buildGraph (Adjacenty_List * const padj, Hash_Table * const pht) ;

int eulerCircuit (Adjacenty_List * const padj, const Hash_Table * const pht, const int start) ;

void depthFirstSearch (Adjacenty_List * const padj, const Hash_Table * const pht, Rqueue * const prq, const int index) ;

int isAnOddExpectZero (const int num) ;

void changeVisited (Adjoin_To_Vertex * const * const vertex, const int hash_value) ;

int splice (Rqueue_Node * const * const scan_1st, Rqueue * const prq_2nd) ;

int main (void)

{

Adjacenty_List adj ;

Hash_Table ht ;

int capacity = SIZE, start = 0 ;

Initialize_A (&adj, capacity) ;

Initialize_H (&ht, capacity * 2) ;

buildGraph (&adj, &ht) ;

eulerCircuit (&adj, &ht, start) ;

Release_A (&adj) ;

Release_H (&ht) ;

return 0 ;

}

void buildGraph (Adjacenty_List * const padj, Hash_Table * const pht)

{

InitializeALine_A (padj, pht, 0, 'a', 2, 4, 'c', 0, 'd', 0) ;

InitializeALine_A (padj, pht, 1, 'b', 2, 4, 'c', 0, 'h', 0) ;

InitializeALine_A (padj, pht, 2, 'c', 6, 12, 'a', 0, 'b', 0, 'd', 0, 'f', 0, 'g', 0, 'i', 0) ;

InitializeALine_A (padj, pht, 3, 'd', 6, 12, 'a', 0, 'c', 0, 'e', 0, 'g', 0, 'j', 0, 'k', 0) ;

InitializeALine_A (padj, pht, 4, 'e', 2, 4, 'd', 0, 'j', 0) ;

InitializeALine_A (padj, pht, 5, 'f', 2, 4, 'c', 0, 'i', 0) ;

InitializeALine_A (padj, pht, 6, 'g', 4, 8, 'c', 0, 'd', 0, 'i', 0, 'j', 0) ;

InitializeALine_A (padj, pht, 7, 'h', 2, 4, 'b', 0, 'i', 0) ;

InitializeALine_A (padj, pht, 8, 'i', 6, 12, 'c', 0, 'f', 0, 'g', 0, 'h', 0, 'j', 0, 'l', 0) ;

InitializeALine_A (padj, pht, 9, 'j', 6, 12, 'd', 0, 'e', 0, 'g', 0, 'i', 0, 'k', 0, 'l', 0) ;

InitializeALine_A (padj, pht, 10, 'k', 2, 4, 'd', 0, 'j', 0) ;

InitializeALine_A (padj, pht, 11, 'l', 2, 4, 'i', 0, 'j', 0) ;

}

int eulerCircuit (Adjacenty_List * const padj, const Hash_Table * const pht, const int start)

{

Rqueue rq_1st, rq_2nd ;

Rqueue_Node * scan ;

int capacity = (*padj) -> capacity, i ;

if (start < 0 || start >= capacity)

return 0 ;

if (!Initialize_R (&rq_1st) || !Initialize_R (&rq_2nd))

return 0 ;

/*Test*/

for (i = 0; i < capacity; i++)

{

if (isAnOddExpectZero ((*padj) -> indegree[i]))

return 0 ;

}

depthFirstSearch (padj, pht, &rq_1st, start) ;

scan = rq_1st -> front ;

while (scan)

{

if ((*padj) -> indegree[scan -> index_in_adjacenty_list])

{

g_last_path = INFINITY ;

depthFirstSearch (padj, pht, &rq_2nd, scan -> index_in_adjacenty_list) ;

scan = scan -> next ;

/*Splicing these two queues*/

splice (&(rq_1st -> front), &rq_2nd) ;

rq_1st -> current = rq_1st -> current + rq_2nd -> current - 1 ;

rq_2nd -> front = rq_2nd -> rear = NULL ;

rq_2nd -> current = 0 ;

}

else

scan = scan -> next ;

}

/*Print the result*/

for (scan = rq_1st -> front; scan; scan = scan -> next)

printf ("%c/n", (*pht) -> lists[(*padj) -> list[scan -> index_in_adjacenty_list].hash_value].name) ;

Release_R (&rq_1st) ;

if (!IsEmpty_R (&rq_2nd))

Release_R (&rq_2nd) ;

return 1 ;

}

void depthFirstSearch (Adjacenty_List * const padj, const Hash_Table * const pht, Rqueue * const prq, const int index)

{

Adjoin_To_Vertex * scan ;

int w ;

// The degree of current vertex--

if (g_last_path != INFINITY)

{

(*padj) -> indegree[index]-- ;

//The path of from Current vertex to previous vertex should be deleted*/

changeVisited (&(*padj) -> list[index].adjoin_to, (*padj) -> list[g_last_path].hash_value) ;

}

Insert_R (prq, index) ;

scan = (*padj) -> list[index].adjoin_to ;

while (scan)

{

/*If he degree of current vertex is 0*/

if (0 == (*padj) -> indegree[(*pht) -> lists[scan -> hash_value].index_in_adjacenty_list])

scan = scan -> next ;

//Else if current vertex is previous vertex*/

else if (g_last_path == (*pht) -> lists[scan -> hash_value].index_in_adjacenty_list)

scan = scan -> next ;

//Else if current vertex has been visited*/

else if (TRUE == scan -> visited)

scan = scan -> next ;

else

break ;

}

if (NULL == scan)

return ;

/*The degree of current vertex--*/

(*padj) -> indegree[index]-- ;

/*The path of from Current vertex to objective vertex should be deleted*/

changeVisited (&(*padj) -> list[index].adjoin_to, scan -> hash_value) ;

g_last_path = index ;

w = (*pht) -> lists[scan -> hash_value].index_in_adjacenty_list ;

depthFirstSearch (padj, pht, prq, w) ;

}

int isAnOddExpectZero (const int num)

{

return 0 != num && num % 2 != 0 ;

}

void changeVisited (Adjoin_To_Vertex * const * const vertex, const int hash_value)

{

if ((*vertex) -> hash_value == hash_value)

(*vertex) -> visited = TRUE ;

else

changeVisited (&(*vertex) -> next, hash_value) ;

}

int splice (Rqueue_Node * const * const scan_1st, Rqueue * const prq_2nd)

{

Rqueue_Node * temp ;

if (*scan_1st)

{

if ((*scan_1st) -> next -> index_in_adjacenty_list == (*prq_2nd) -> front -> index_in_adjacenty_list)

{

temp = (*scan_1st) -> next ;

(*scan_1st) -> next = (*prq_2nd) -> front ;

(*prq_2nd) -> rear -> next = temp -> next ;

free (temp) ;

return 1 ;

}

else

splice (&(*scan_1st) -> next, prq_2nd) ;

}

else

return 0 ;

}

欧拉方法c语言程序,欧拉回路算法C语言相关推荐

  1. c语言编程欧拉方法求近似值,欧拉法求解已知初值微分方程解

    1.原理 数值积分算法是求解知初值的微分方程的重要方法. 如已知微分方程 d(y)/d(t) = f(y, t) y(t0) = y0 方程两边对t积分就会有 此式表示原函数t1时刻的解y(t1)为原 ...

  2. 隐式欧拉解常微分方程c语言,利用欧拉方法求常微分方程近似数值解.doc

    利用欧拉方法求常微分方程近似数值解,欧拉微分方程,欧拉运动微分方程,欧拉平衡微分方程,欧拉型微分方程,微分方程的欧拉算法,微分方程的欧拉解法,欧拉型常微分方程,偏微分方程数值解,微分方程数值解法 利用 ...

  3. 【微分方程数值解】常微分方程(一)欧拉方法和改进欧拉方法(附python算例,封装类)

    欧拉方法与改进欧拉方法 一.算法原理 对给定微分方程 {y′=f(x,y)y(x0)=y0(1)\begin{cases} y' = f(x,y)\\ y(x_0) = y_0 \end{cases} ...

  4. 6.1 欧拉方法与改进欧拉方法

    6.1.1 欧拉方法 欧拉方法是一种数值解常微分方程(ODE)的方法,可以用于近似求解给定的初值问题.它是以欧拉命名的瑞士数学家莱昂哈德·欧拉所发明的,因此得名. 欧拉方法的基本思路是将连续的常微分方 ...

  5. 计算机图形学【GAMES-101】14、动画(物理模拟、质点弹簧系统、粒子系统、运动学、动作捕捉、欧拉方法)

    快速跳转: 1.矩阵变换原理Transform(旋转.位移.缩放.正交投影.透视投影) 2.光栅化(反走样.傅里叶变换.卷积) 3.着色计算(深度缓存.着色模型.着色频率) 4.纹理映射(重心坐标插值 ...

  6. 欧拉方法的一点理解(基本原理,推导公式)

    本文只是作者的一点点理解,初衷是让小白看懂数学,去理解,而不是刻板的记公式,纯手敲,希望多多关注,大佬可以指点,但别喷我. 本文的前提是常微分方程,很多地方我就不过多的讲解前提条件了,读者只要知道,一 ...

  7. 微分方程数值解法(欧拉方法)

    微分方程数值解法(欧拉方法) 假设y'=-x/y,这里采用分离变量法可以得到x^2+y^2=C,是一个圆: 现在假设C=4,并且有初始值为(-2,0),比较用数值方法获得的值与用公式计算的值之间的误差 ...

  8. 图形学笔记(二十)粒子、刚体、流体的模拟—— 欧拉方法、Errors 和 Instability、中点法、自适应步长、隐式欧拉方法、Runge-Kutta方法、刚体与流体模拟(质点法、网格法、MPM)

    图形学笔记(十九)粒子.刚体.流体的模拟-- 欧拉方法.Errors 和 Instability.中点法.自适应步长.隐式欧拉方法.Runge-Kutta方法.刚体与流体模拟(质点法.网格法.MPM) ...

  9. 微分方程的数值解法之欧拉方法

    '''欧拉方法''' #所求常微分方程 f_x=input('y\'=') def fy(x,y):return eval(f_x)#原方程的精确解 f_e=input('y =') def fe(x ...

最新文章

  1. 垂直margin合并问题
  2. c++内存分配的方式
  3. CodeForces - 528D Fuzzy Search(多项式匹配字符串)
  4. 大公司稳定工作和创业之间如何选择?
  5. 向量叉乘判断两向量之间是顺时针还是逆时针
  6. STM32H743+CubeMX-ADC(16bit分辨率)+DMA采样三路模拟量,硬件过采样器实现1024倍过采样
  7. pod中mysql配置文件修改_通过configmap更新k8s里的mysql配置文件
  8. 浙江使用计算机的用量,现在全世界计算机的使用量是多少
  9. mysql中生成列与JSON类型的索引
  10. 中文信息处理(六)—— 神经语言模型与词表示(word2vec)
  11. java 重复流_Java Logger控制台流重复输出 - java
  12. 深入浅出通信原理知识点10
  13. 全球时报英语新闻爬虫
  14. 五个维度打造研发管理体系
  15. LookAhead优化器方法
  16. mysql 分段执行_mySql 分段查询
  17. 44.android 简单的白天与夜晚模式切换
  18. matlab最基础教程(二):变量类型与赋值
  19. git与gitee的基础使用方法
  20. 爬取猫眼top100数据,并保存到excel

热门文章

  1. stm32学习笔记-6TIM定时器
  2. directx实现过程和原理
  3. INtouch与 ModbusTCP通讯
  4. SOLIDWORKS模版的建立
  5. QLExpress 规则引擎
  6. MySQL可重复读事务隔离具体是怎么实现的?
  7. vue原理:vue中是如何监听数组变化?
  8. java里shake是什么意思_在英文里shake是什么意思意思 , 英语单词shake中文是什么啊...
  9. 文献学习-摘抄 基于动力学一致性的高速公路卡车编队控制研究
  10. Hive考试练习题(参考题解)