473,320 Members | 1,988 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 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 2324
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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.