Click here to Skip to main content
15,922,015 members
Home / Discussions / Algorithms
   

Algorithms

 
GeneralRe: OPT Replacement Policy Pin
Alan Balkany6-Jan-09 4:03
Alan Balkany6-Jan-09 4:03 
GeneralRe: OPT Replacement Policy Pin
Mustafa Ismail Mustafa6-Jan-09 4:18
Mustafa Ismail Mustafa6-Jan-09 4:18 
AnswerRe: OPT Replacement Policy Pin
Pete O'Hanlon5-Jan-09 5:01
mvePete O'Hanlon5-Jan-09 5:01 
GeneralRe: OPT Replacement Policy Pin
Mustafa Ismail Mustafa5-Jan-09 8:45
Mustafa Ismail Mustafa5-Jan-09 8:45 
Questionshortest paths from s to every vertex of G Pin
nicoletsgr3-Jan-09 10:13
nicoletsgr3-Jan-09 10:13 
AnswerRe: shortest paths from s to every vertex of G Pin
Tony Pottier3-Jan-09 13:27
Tony Pottier3-Jan-09 13:27 
GeneralRe: shortest paths from s to every vertex of G Pin
Tony Pottier3-Jan-09 13:32
Tony Pottier3-Jan-09 13:32 
AnswerRe: shortest paths from s to every vertex of G Pin
valiantljk6-Jan-09 5:07
valiantljk6-Jan-09 5:07 
The following is the C codes ,you can refer to it if needed.

#include<stdio.h>
#include<malloc.h>
#define MAXV 20
#define INF 32767
typedef struct
{
int edges[MAXV][MAXV];
int n;
} MGraph;

void Ppath(int path[],int i,int v)
{
int k;
k=path[i];
if(k==v) return;
Ppath(path,k,v);
printf("%d,",k);
}
void PRINTF(int dist[],int path[],int s[],int n,int v)
{
int i;
for(i=0;i&lt;n;i++)
{
if(i==v) continue;
if(s[i]==1)
{
printf("from%dto%d,the shortestpath is:%d\t:",v,i,dist[i]);
printf("%d,",v);
Ppath(path,i,v);
printf("%d\n",i);
}
else printf("from%dto%ddoesn't exits a path\n",v,i);
}
}
void Dijkstra(MGraph p,int v)
{
int dist[MAXV],path[MAXV];
int s[MAXV];
int mindis,i,j,u;
for(i=0;i&lt;p.n;i++)
{
dist[i]=p.edges[v][i];
s[i]=0;
if(p.edges[v][i]&lt;INF) path[i]=v;
else path[i]=-1;
}
s[v]=1;path[v]=0;
for(i=0;i&lt;p.n;i++)
{
mindis=INF;
for(j=0;j&lt;p.n;j++)
{
if(s[j]==0&amp;&amp;dist[j]&lt;mindis)
{
u=j;
mindis=dist[j];
}
}
s[u]=1;
for(j=0;j&lt;p.n;j++)
{
if(s[j]==0)
{
if(p.edges[u][j]&lt;INF&amp;&amp;dist[u]+p.edges[u][j]&lt;dist[j])
{
dist[j]=dist[u]+p.edges[u][j];
path[j]=u;
}
}
}
}
PRINTF(dist,path,s,p.n,v);

}
int main()
{
int i,j,n,x;
MGraph p;
printf("please input the number of the vertex of the directed graph:");
scanf("%d",&n);
while(n!=0)
{
printf("please input the adjacency matrix of the directed graph:\n");
for(i=0;i&lt;n;i++)
{
for(j=0;j&lt;n;j++)
{
scanf("%d",&p.edges[i][j]);
}
}
p.n=n;

printf("which vertex you want to search?(0--%d):\n end inputing with%d\n",n-1,n);
scanf("%d",&x);
while(x!=n)
{
Dijkstra(p,x);printf("\n");
printf("which vertex you want to search?(0--%d):\n end searching with %d:\n",n-1,n);
scanf("%d",&amp;x);
}
printf("over!\n");
printf("please input the number of the vertex of the directed graph,
input 0 if you want to quit:\n");
scanf("%d",&n);
}
return 0;
}
AnswerRe: shortest paths from s to every vertex of G Pin
Mustafa Ismail Mustafa6-Jan-09 6:10
Mustafa Ismail Mustafa6-Jan-09 6:10 
QuestionA matter of size - the size of the search space Pin
Mustafa Ismail Mustafa30-Dec-08 23:26
Mustafa Ismail Mustafa30-Dec-08 23:26 
AnswerRe: A matter of size - the size of the search space Pin
73Zeppelin31-Dec-08 1:59
73Zeppelin31-Dec-08 1:59 
GeneralRe: A matter of size - the size of the search space Pin
Mustafa Ismail Mustafa31-Dec-08 2:42
Mustafa Ismail Mustafa31-Dec-08 2:42 
GeneralRe: A matter of size - the size of the search space Pin
73Zeppelin31-Dec-08 3:01
73Zeppelin31-Dec-08 3:01 
Questionmpeg decoding Pin
plewand29-Dec-08 0:31
plewand29-Dec-08 0:31 
AnswerRe: mpeg decoding Pin
bulg29-Jan-09 12:15
bulg29-Jan-09 12:15 
QuestionThis is all about Decision Support System... Pin
surfJul26-Dec-08 5:15
surfJul26-Dec-08 5:15 
AnswerRe: This is all about Decision Support System... Pin
73Zeppelin28-Dec-08 5:24
73Zeppelin28-Dec-08 5:24 
AnswerRe: This is all about Decision Support System... Pin
Alan Balkany28-Dec-08 7:09
Alan Balkany28-Dec-08 7:09 
QuestionCrystal Report Pin
dkkeyan25-Dec-08 22:24
dkkeyan25-Dec-08 22:24 
QuestionA* & Genetic Algorithms Pin
Mustafa Ismail Mustafa25-Dec-08 5:52
Mustafa Ismail Mustafa25-Dec-08 5:52 
AnswerRe: A* & Genetic Algorithms Pin
73Zeppelin28-Dec-08 5:21
73Zeppelin28-Dec-08 5:21 
GeneralRe: A* & Genetic Algorithms Pin
Mustafa Ismail Mustafa28-Dec-08 5:27
Mustafa Ismail Mustafa28-Dec-08 5:27 
GeneralRe: A* & Genetic Algorithms Pin
73Zeppelin28-Dec-08 5:31
73Zeppelin28-Dec-08 5:31 
GeneralRe: A* & Genetic Algorithms Pin
Mustafa Ismail Mustafa28-Dec-08 5:35
Mustafa Ismail Mustafa28-Dec-08 5:35 
GeneralRe: A* & Genetic Algorithms Pin
73Zeppelin28-Dec-08 5:41
73Zeppelin28-Dec-08 5:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.