473,473 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Dijkstra's algorithm

momotaro
357 Contributor
am having a final tomorrow am not yet done with dijkstra!!!
plz help this is my code waht is wrong with it!

Expand|Select|Wrap|Line Numbers
  1. void Dijkstra(char *root, char *destination, GraphNode *head)
  2. {
  3.     GraphNode *Root, *dest, *GraphNodeWalker, *vertmin;
  4.     ListNode *ListNodeWalker;
  5.     int flag;
  6.  
  7.  
  8.     /*set the root */
  9.  
  10.     Root = FindVertex(head,root);
  11.  
  12.     distance[Root->num] = 0;
  13.     visited1[Root->num] = 1;
  14.     /* set adjacent to the root */
  15.  
  16.     for(ListNodeWalker = Root->HeadAdjacencyList; ListNodeWalker; ListNodeWalker = ListNodeWalker->NextListNode)
  17.     {
  18.         if(strcmp(root,ListNodeWalker->IP) != 0)
  19.         {
  20.             distance[(FindVertex(head, ListNodeWalker->IP))->num] = ListNodeWalker->weight; //problem is here
  21.             path[(FindVertex(head, ListNodeWalker->IP))->num] = Root;
  22.         }
  23.     }
  24.     /* find the destination vertex and beggan the loop */
  25.  
  26.     dest = FindVertex(head, destination);
  27.  
  28.     while( visited1[dest->num] == 0)  /* until the destination vertex is found */
  29.     {
  30.         flag=0;
  31.         for(GraphNodeWalker = head; GraphNodeWalker; GraphNodeWalker = GraphNodeWalker->NextGraphNode)
  32.         {
  33.             if(visited1[GraphNodeWalker->num]==0 && flag==0)
  34.             {
  35.                 vertmin=GraphNodeWalker;
  36.                 flag=1;
  37.             }
  38.  
  39.             if(flag==1 && distance[GraphNodeWalker->num] < distance[vertmin->num] && visited1[GraphNodeWalker->num] == 0)
  40.             {
  41.                 vertmin = GraphNodeWalker;
  42.             }
  43.         }
  44.  
  45.         visited1[FindVertex(head,vertmin->IP)->num] = 1;
  46.  
  47.         for(ListNodeWalker = vertmin->HeadAdjacencyList; ListNodeWalker; ListNodeWalker = ListNodeWalker->NextListNode)
  48.         {
  49.             if(distance[FindVertex(head, ListNodeWalker->IP)->num]>distance[FindVertex(head,vertmin->IP)->num] + ListNodeWalker->weight)
  50.             {
  51.                 distance[FindVertex(head, ListNodeWalker->IP)->num] = distance[FindVertex(head,vertmin->IP)->num] + ListNodeWalker->weight;
  52.                 path[FindVertex(head, ListNodeWalker->IP)->num] = FindVertex(head,vertmin->IP);
  53.             }
  54.         }
  55.     }
  56. }
  57.  
Jul 17 '07 #1
0 1633

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Ricardo Batista | last post by:
I need that someone help me. I need to program the dijkstra algorithm by object oriented. I'll send my code. #!/usr/bin/env python # -*- encoding: latin -*- NIL =
6
by: ThanhVu Nguyen | last post by:
Hi all, I need recommendation for a very fast shortest path algorithm. The edges are all directed, positive weights. Dijkstra shortest path will solve it just fine but the if the graph is not...
3
by: A_StClaire_ | last post by:
implemented Dijkstra's algorithm as follows. plz pour on the negative criticism cuz I know I have a ton to learn. oh, before you flame me regarding the language, my class was told to do this in...
3
by: Ook | last post by:
This is probably a bit OT, as I'm not looking for a c++ implementaiton of Dijkstra's algorithm, rather I'm just trying to understand it (is there a better place then here to ask this question?)....
1
by: arlef | last post by:
Can somebody please explain and provide pseudocode for the Dijkstra algorithm? I'm trying to implement the Dijkstra shortest path algorithm. However, I'm finding it extremely difficult to...
9
by: Josh Zenker | last post by:
I've been working on an implementation of Dijkstra's algorithm on and off for the past few days. I thought I was close to being finished, but clearly I've done something wrong. I'm not a very...
8
by: abhradwip | last post by:
I want to write a program which will find the shortest path between n no. of cities using dijkstra's algorithm ...... but could not do it..... i have written a program which will give the shortest...
1
Ganon11
by: Ganon11 | last post by:
Hey guys, I'm back, and with another FUN question! My latest homework asks this question: "Suppose all the edge weights in a graph are integers between 1 and |E|. How fast can Dijkstra's...
2
by: shashankbs | last post by:
Given a topology and a certain node X, find the shortest path tree with X as the root. * Input: a topology file similar to the following (which is a three-node ring) ...
1
by: Glenton | last post by:
Hi All Here is a very simple little class for finding a shortest route on a network, following Dijkstra's Algorithm: #!/usr/bin/env python #This is meant to solve a maze with Dijkstra's...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.