472,784 Members | 995 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,784 software developers and data experts.

dijkstras algorithm

Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2.  
  3. int main()
  4. {
  5.     int a,b,w,v,e,i;
  6.     int g[20][20],visited[20],d[20],p[20];
  7.     printf("enter the number of vertices");
  8.     scanf("%d",&v);
  9.     printf("enter the number of edges");
  10.     scanf("%d",&e);
  11.     for(i=1;i<=v;i++)
  12.     {
  13.         for(int j=1;j<=v;j++)
  14.         {
  15.             g[i][j]=0;
  16.         }
  17.     }
  18.     for(i=1;i<=e;i++)
  19.     {
  20.         printf("enter edge info");
  21.         scanf("%d",&a);
  22.         scanf("%d",&b);
  23.         printf("enter weight of the edge");
  24.         scanf("%d",&w);
  25.         g[a][b]=g[b][a]=w;
  26.     }
  27.     void calldij()
  28.       {
  29.         for(i=1;i<=v;i++)
  30.         {
  31.             p[i]=visited[i]=0;
  32.         }
  33.         for(i=1;i<=v;i++)
  34.         {
  35.             d[i]=32767;
  36.         }
  37.         dij();
  38.       }
  39.  
  40.     void dij()
  41.     {
  42.         int current,source,dest;
  43.         printf("enter source and destination vertex");
  44.         scanf("%d",&source);
  45.         scanf("%d",&dest);
  46.  
  47.         current=source;
  48.         visited[current]=1;
  49.         d[current]=0;
  50.         while(current!=dest)
  51.         {
  52.             int dc=d[current];
  53.             for(i=1;i<=v;i++)
  54.             {
  55.                 if((g[current][i]!=0) && (visited[i]!=1))
  56.                 {
  57.                 if((g[current][i]+dc)<(d[i]))
  58.                  {
  59.                     d[i]=(g[current][i]+dc);
  60.                     p[i]=current;
  61.                  }
  62.                 }
  63.             }
  64.             int min=32767;
  65.             for(i=1;i<=v;i++)
  66.             {
  67.                 if((visited[i]!=1) && (d[i]<min))
  68.                 {
  69.                     min=d[i];
  70.                     current=i;
  71.                 }
  72.             }
  73.             visited[current]=1;
  74.         }
  75.         printf("shortest distance= %d",d[dest]);
  76.     }
  77.     return 0;
  78.  
  79. }
Error on 2nd line of the function dij() and calldij() (declaration syntax error)
Please revert as soon as possible. URGENT!
Dec 20 '09 #1
5 2293
Banfa
9,065 Expert Mod 8TB
You can not declare functions inside functions in C/C++
Dec 20 '09 #2
MrPickle
100 100+
Also, dij() need to come before calldij() because calldij() is calling dij(), or you can pre-define it.
Dec 20 '09 #3
alexis4
113 100+
The structure of this program should be as following:

Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2.  
  3. void calldij (void);
  4. void dij (void);
  5.  
  6. int main (void)
  7. {
  8. }
  9.  
  10. void calldij (void)
  11. {
  12. }
  13.  
  14. void dij (void)
  15. {
  16. }
  17.  
Dec 20 '09 #4
yes i understood my mistake ..dijakstras algorithm is working properly now ..but i have to perform simuation of routing protocol .dijakstras also is jst a part of link state routing ..can u plzz suggest me some site where i can understand the concept to print the tables (routing tables ) at each hop .URGENT
Dec 24 '09 #5
alexis4
113 100+
There is a forum for algorithms in this site. See at the top and right of this very page and you will see it. Post your question there!
Dec 25 '09 #6

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

Similar topics

6
by: Jack Smith | last post by:
Hello, any help appreciated with following problem. I figured out the algorithm (I think), just having trouble proving it is optimal. Suppose we are given n tasks each of which takes 1 unit...
16
by: cody | last post by:
I have to write an algorithm with must ensure that objects are put in buckets (which are always 4 in size). The objects have two properties: A and B. It is not allowed that in a bucket are objects...
10
by: bpontius | last post by:
The GES Algorithm A Surprisingly Simple Algorithm for Parallel Pattern Matching "Partially because the best algorithms presented in the literature are difficult to understand and to implement,...
32
by: Cmorriskuerten | last post by:
HI, is this is this solution to test if a number is a prime number or not: /* * Is n a prime number? * Return TRUE (1): n is a prime number * Return FALSE (0): n is a *not* a prime number...
113
by: Bonj | last post by:
I was in need of an encryption algorithm to the following requirements: 1) Must be capable of encrypting strings to a byte array, and decyrpting back again to the same string 2) Must have the same...
4
by: FBM | last post by:
Hi, I am working on a program that simulates one of the elements of ATM. The simulation stores events which occurs every some milliseconds for a certain amount of time. Every time that an event...
2
by: Julio C. Hernandez Castro | last post by:
Dear all, We have just developped a new block cipher called Raiden, following a Feistel Network structure by means of genetic programming. Our intention now consists on getting as much feedback...
4
by: thomasau | last post by:
Hi everyone ! Can someone point me to a good and simple implementation of the Dijkstras algorithm using C . Thanks! -Thomas
0
by: aruna | last post by:
hey guys i earlier had very valuable responses from you all for base64 encoding algorithm.so thank for that. so now i need your assistance to do a float encoding algorithm. you may wonder why i'm...
1
by: almurph | last post by:
Hi everyone, Concerning the Needleman-Wunsch algorithm (cf. http://en.wikipedia.org/wiki/Needleman-Wunsch_algorithm) I have noticed a possible loop. Inside the algorithm there is an...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.