![]() |
![]() |
![]() |
|||||
![]() |
![]() |
![]() |
![]() |
![]() |
|||
| Welcome
to Tech Support Forum home to more then 136,000 problems solved. Issues
have included: Spyware, Malware, Virus Issues, Windows, Microsoft,
Linux, Networking, Security, Hardware, and Gaming Getting your
problem solved is as easy as: 1. Registering for a free account 2. Asking your question 3. Receiving an answer Registered members: * See fewer ads. * And much more..
|
| Want to know how to post a question? click here | Having problems with spyware and pop-ups? First Steps |
|
|||||||
| Programming A discussion forum for programs and programming used in tech-related businesses. |
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) |
|
Registered User
Join Date: Jul 2008
Posts: 2
OS: ubuntu
|
Dijkstra
this is the code i ve written for dijkstra in c for linux(ubuntu).. there is some error in it can u help me rectify it.. thanks
#include <stdio.h> void main() { int i,j,k,graph[5][5],dist[5][5],visited[5][5],prev[5][5],q[5],least,least_node,sum,alt; // vist=visited or no q=set of al nodes for(i=0;i<5;i++) { for(j=0;j<5;j++) { if(i==j) { graph[i][j]=-1; } else { printf("Enter value from %d to %d:",i,j); scanf("%d",&graph[i][j]); } dist[i][j]=-1; visited[i][j]=0; } } for (i=0;i<5;i++) { least=9999; sum=0; // Finding least node for(j=0;j<5;j++) { if((graph[i][j]!=-1)&&(least>graph[i][j] )) { least=graph[i][j]; least_node=j; } } sum+=least; dist[i][least_node]=least; visited[i][least_node]=1; visited[least_node][i]=1; for(k=0;k<5;k++) { //while((graph[least_node][k]!=-1)&&(visited[least_node][k]!=1)){ if((graph[least_node][k]!=-1)&&(visited[least_node][k]!=1)) { alt=sum+graph[least_node][k]; if((graph[i][k]>alt)||(graph[i][k]==-1)) { dist[i][k]=alt; prev[i][k]=least_node; } } else { dist[i][k]=graph[i][k]; prev[i][k]=i; } } } for(i=0;i<5;i++){ for(j=0;j<5;j++){ printf("%d\n",dist[i][j]); } } } |
|
|
|
| Important Information |
|
Join the #1 Tech Support Forum Today - It's Totally Free!
TechSupportForum.com is a leading support website for your computer needs. We offer free, friendly and personalized computer support. Why pay to have your computer fixed when you can do it for free. Join TechSupportforum.com Today - Click Here |
|
|
#3 (permalink) |
|
Registered User
Join Date: Oct 2007
Location: Littleton, Colorado USA
Posts: 470
OS: xp 64 sp2 Fedora Core 8 (vmware xp core 8 x32) Minix
|
Re: Dijkstra
Compiled fine and ran OK. Have no idea what you are doing! But it didn't core dump. Are you using "vi" as your editor? If not use it and learn the "%" command. Lay the cursor on a brace, curley, square, or parenthesis and then enter the %. VI will show you the other closing brace. VI did get confused on the "//" comment line on line 65, because it had unclosed braces. I just deleted the line to make it work.
Learn the VI editor and the cntl-Z command to stop the edit session. Use "fg" to bring the edit session back to the foreground. Don't forget to save the C-file before you cntl-Z. The "jobs" command will show the stop programs. This method works very well for code writing and your hands don't have to leave the keyboard. Sorry I don't do homework. The code seemed error free except for "void main()" which is not C90 or C99 (I think). The main should return an integer status value. The gcc compiler flagged that as warning. |
|
|
|
|
|
#4 (permalink) |
|
Manager
Join Date: Sep 2004
Location: Colorado
Posts: 987
OS: Mac OS 9.1, Mac OS X 10.5.8, WinXP Pro, FreeBSD 6.0, Gentoo Linux
|
Re: Dijkstra
What exactly is not working? Give us specific error messages, etc.
I recommend changing void main() to int main( void ), then you should have return 0; at the bottom of your main function. Please indent your code and post with code tags around it.
__________________
![]() Has it been a few days since I replied to your thread? Don't panic! I'm a busy college student and may forget a post if I'm extra busy (or it might just take me a while to be able to do a decent reply). If you still need help and are awaiting my reply after a few days, PM me about it. When posting what errors you get, please give the full message. It makes helping you much easier. |
|
|
|
![]() |
| Thread Tools | |
|
|