Thread: shortest path algorithm prob

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    34

    shortest path algorithm prob

    i nid to find out wat is the shortest path....
    user will input values.. then input where wil be his entrnce and exit..


    ent_y is the column and ent_x is the row of the entrance entered by the user
    ex_y is the column and ex_x is the row of the exit entered also by the user

    all values that are added to charing
    here's the code... there is something wrong w/ this...i stil cnt find the shortest path

    Code:
    	if(ent_y<ex_y&&ent_x<ex_x)
    	{
    	  for(ai=ent_y;ai<ex_y;ai++)
    	  {  if(ent_x==ex_x)
    			{ for(bo=ent_y;bo<ex_y;bo++)
    				{bad+=path[ent_x][bo];
    				}
    				charing+=bad;
    			}
    		if(path[ent_y+1][ent_x]<path[ent_y][ent_x+1])
    		{
    			dong:
    			if(ent_y+1==ex_y)
    			{ for(bo=ent_x;bo<ex_x;bo++)
    				{bad+=path[ent_y+1][bo];
    				}
    				charing+=bad;
    			}
    			else
    			charing+=path[ent_y+1][ent_x];
    		}
    		else if(path[ent_y+1][ent_x]>path[ent_y][ent_x+1])
    			{
    				dang:
    				charing+=path[ent_y][ent_x+1];
    				ai=ent_y;
    				ent_x=ent_x+ent_x+1;
    			}
    		else
    			{
    				if(path[ent_y][ent_x+2]>path[ent_y+2][ent_x])
    				{goto dong;}
    				 else goto dang;
    			}
    		}
    	  }
    		    got(30,15); cprintf("value: %d",charing);

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Eww..... goto...... this is ugly...... Sorry, but this is going to be hard to walk through.

  3. #3
    Registered User
    Join Date
    Dec 2006
    Posts
    34
    can u suggest a code that will help me determine the shortest path??

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Shortest Path Maze Solver (Breadth Search Help)
    By Raskalnikov in forum C Programming
    Replies: 5
    Last Post: 04-07-2009, 07:41 PM
  2. Shortest path algorithm with a maximum number of edges limit
    By blackslither in forum C Programming
    Replies: 4
    Last Post: 12-28-2008, 04:49 PM
  3. Need help finding a simple 'shortest path' algorithm
    By ashley in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 12:38 PM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. shortest path algorithm and file saving
    By Micko in forum C++ Programming
    Replies: 0
    Last Post: 05-07-2004, 12:01 PM