【计算机论文全套栏目提醒】:文章导读:在新的一年中,各位网友都进入紧张的学习或是工作阶段。
网学会员整理了计算机论文全套-Dijkstra算法完整实现源代码 - 计算机理论的相关内容供大家参考,祝大家在新的一年里工作和学习顺利!
Dijkstra算法的完整实现版本算法的源代码 / Dijkstra.c Copyright c 2002 2006 by ctu_85 All Rights Reserved. / include stdio.h include malloc.h define maxium 32767 define maxver 9 /defines the max number of vertexs which the programm can handle/ define OK 1 struct Point char vertex3 struct Link work struct Point next struct Link char vertex3 int value struct Link next struct Table /the workbannch of the algorithm/ int cost int Known char vertex3 char path3 struct Table next int Dijkstrastruct Point struct Table int PrintTableintstruct Table int PrintPathintstruct Table struct Table struct Table CreateTableintint struct Point FindSmalleststruct Table struct Point /Find the vertex which has the smallest value reside in the table/ int main int ijnumtempval char c struct Point poinprepoinheadpoin struct Link linprelinheadlin struct Table tabhead poinprepoinheadpoinstruct Point mallocsizeofstruct Point poin-nextNULL poin-workNULL restart: printfNotice:if you wanna to input a vertexyou must use the format of numbern printfPlease input the number of points:n scanfdnum ifnummaxvernumvertex0v poin-vertex10i1 poin-vertex20 linprelinpoin-work linpre-nextNULL forj0jnextNULL break else linstruct Link mallocsizeofstruct Link linpre-nextlin lin-vertex0v lin-vertex10temp lin-vertex20 printfPlease input the value betwixt d th point towards d th point:i1temp scanfdval lin-valueval linprelinpre-next lin-nextNULL poinprepoinpre-next poin-nextNULL printfPlease enter the vertex where Dijkstra algorithm starts:n scanfdtemp tabheadCreateTabletempnum Dijkstrapoinheadtabhead PrintTabletemptabhead return OK struct Table CreateTableint vertexint total struct Table headprep int i headprepstruct Table mallocsizeofstruct Table p-nextNULL fori0inextp ifi1vertex p-vertex0v p-vertex10i1 p-vertex20 p-cost0 p-Known0 else p-vertex0v p-vertex10i1 p-vertex20 p-costmaxium p-Known0 p-nextNULL prepre-next return head int Dijkstrastruct Point p1struct Table p2 / Core of the programm/ int costs char temp struct Point poinheadp1now struct Link linna struct Table tabheadp2searcresult while1 nowFindSmallesttabheadpoinhead ifnowNULL break resultp2 resultresult-next whileresultNULL ifresult-vertex1now-vertex1 break else resultresult-next linnanow-work-next whilelinnaNULL / update all the vertexs linked to the signed vertex/ templinna-vertex1 searctabhead-next whilesearcNULL ifsearc-vertex1temp/find the vertex linked to the signed vertex in the table and update/ ifresult-costlinna-valuecost searc-costresult-costlinna-value/set the new value/ searc-path0v searc-path1now-vertex1 searc-path20 break else searcsearc-next linnalinna-next return 1 struct Point FindSmalleststruct Table headstruct Point poinhead struct Point result struct Table temp int minmaxiumstatus0 headhead-next poinheadpoinhead-next whileheadNULL ifhead-Knownhead-costcost resultpoinhead temphead status1 headhead-next poinheadpoinhead-next ifstatus temp-Known1 return result else return NULL int PrintTableint startstruct Table head struct Table beginhead