Skip to main content

Posts

Showing posts from 2018

Finding Shortest Path From Source to Destination using dijkstra algorithm usinc C program.

#include<stdio.h>
#include<conio.h>
#define IN 9999
#define MAX 10

void dj(int G[MAX][MAX],int n,int startnode,int dst);
void main()
{
int j,i,node,con[10][10],s,d;
clrscr();
printf("Enter No of Nodes::");
scanf("%d",&node);
for(i=0;i<node;i++)
{
for(j=0;j<node;j++)
{

printf("Node %d is conneted with node %d::",i,j);
a:
scanf("%d",&con[i][j]);
if(con[i][j]!=0 && con[i][j]!=1)
{
goto a;
}
}
}
printf("MATRIX:");
for(i=0;i<node;i++)
{
printf("\n");
for(j=0;j<node;j++)
{
printf("%d ",con[i][j]);
}
}

printf("\nENTER SOURCE & DESTINATION::");
scanf("%d%d",&s,&d);
dj(con,node,s,d);

}














void dj(int G[MAX][MAX],int n,int startnode,int dst)
{

    int cost[MAX][MAX],distance[MAX],pred[MAX];
    int visited[MAX],count,mindistance,nextnode,i,j;


    for(i=0;i<n;i++)
for(j=0;j<n;j++)
    if(G[i][j]==0)
cost[i][j]=IN;
    else
cost[i][j]=G[i][j];

    for(i=0;i<n;i++)
    {
distance[i]=cost[startnode][i…