: Implement Diijkstra’s algorithm to compute the shortest path through a graph
#1

Code:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
  char nod[10],st,ed;
  int wts[10][10],n,i,j,k,x=0,y,s=0,pos=-1,max=100;
  clrscr();
  printf("Enter the no of nodes:");
  scanf("%d",&n);
  printf("Enter nodes:");
  for(i=0;i<n;i++)
  {
    fflush(stdin);
    scanf("%c",&nod[i]);
  }
  printf("Enter start & end node:");
  fflush(stdin);
  scanf("%c",&st);
  fflush(stdin);
  scanf("%c",&ed);
  for(i=0;i<n;i++)
  {
    
y=0;
      for(j=0;j<n;j++)
      {
      printf("Wt between%c-%c:",nod[x],nod[y]);
      scanf("%d",&wts[i][j]);
      y++;
     }
     x++;
     }
     printf("\n");
     //printing table
     for(x=0;x<n;x++)
     printf("\t %c",nod[x]);
     printf("\n----------------------------\n");
     for(i=0;i<n;i++)
     {
       printf("%c",nod[i]);
       for(j=0;j<n;j++)
       printf("\t %d",wts[i][j]);
       printf("\n");
     }
     printf("-------------------------------------");
     //finding pos of first node
     for(i=0;i<n;i++)
     {
    

pos++;
    if(nod[i]==st)
    break;
      }
      printf("\n pos=%c",nod[pos]);
      //implement spa
      for(k=0;k<n;k++)
      {
     for(x=0;x<n;x++)
     if(wts[pos][x]!=0&&max>wts[pos][x])
     {
       max=wts[pos][x];
       y=x;
     }
     printf("\n pos=%c",nod[y]);
     s=s+max;
     max=100;
     if(nod[y]!=ed)
     {
        pos=-1;
        for(i=0;i<n;i++)
        {
        pos++;
        if(nod[i]==nod[y])
        break;
      
  }
     }
     else
     break;
       }
       printf("\n Shortest path:%d",s);
       getch();
     }
Reply

Important Note..!

If you are not satisfied with above reply ,..Please

ASK HERE

So that we will collect data for you and will made reply to the request....OR try below "QUICK REPLY" box to add a reply to this page
Popular Searches: how to implement a new technology system, shortest path find algorithm in network, scanf c nod i, what is graph search as tree search, tybsc compute science quetion paper dawnload, matlab graph cut algorithm code, what is graph transformation algorithm for video subsequence,

[-]
Quick Reply
Message
Type your reply to this message here.

Image Verification
Please enter the text contained within the image into the text box below it. This process is used to prevent automated spam bots.
Image Verification
(case insensitive)

Possibly Related Threads...
Thread Author Replies Views Last Post
  Implement DES Algorithm smart paper boy 1 3,916 16-02-2012, 12:34 PM
Last Post: seminar paper
  Program to Encrypt and decrypt a text data using RSA algorithm smart paper boy 0 2,524 10-08-2011, 11:43 AM
Last Post: smart paper boy
  Program to implement the data link layer framing method character stuffing smart paper boy 0 7,947 10-08-2011, 11:41 AM
Last Post: smart paper boy
  Program to implement the data link layer framing method bit stuffing smart paper boy 0 2,891 10-08-2011, 11:41 AM
Last Post: smart paper boy
  Program in “C” to implement NFA seminar class 0 1,868 07-05-2011, 12:52 PM
Last Post: seminar class
  Program in “C” to implement DFA. seminar class 0 2,115 07-05-2011, 12:51 PM
Last Post: seminar class
  C PROGRAM TO IMPLEMENT NOISE CANCELLATION seminar class 0 2,153 06-05-2011, 04:23 PM
Last Post: seminar class
  C PROGRAM TO IMPLEMENT FIR FILTER seminar class 0 2,666 06-05-2011, 04:09 PM
Last Post: seminar class

Forum Jump: