i am a beginner, guys plizzzzzzzz help me. i am given a assignment to find short paths either using dijkstra algorithm or using binary search algorithm in linux OS.
check out what is wrong the code i tried
/program to find shortest path -
#include<stdio.h>
-
#include<cstdlib>
-
#include<cstring>
-
#include<fstream>
-
#include<iostream.h>
-
#define member 1 // use to indicate current node
-
#define nonmember 0
-
#define infinity 999 // intial distance
-
struct arc
-
{
-
int wt;
-
};
-
struct arc g[10][10];
-
int path[10];
-
//end of global defintn
-
void jointwt(struct arc g[][10], int n1, int n2 ,int wt)
-
// function to assign the weight on arcs
-
{
-
g[n1][n2].wt = wt; // assign the weight to arc n1 -n2
-
}
-
// end of function joint
-
cost(struct arc c[][10], int n)
-
// function to get the weights
-
{
-
int i,j,wt;
-
for(i=0;i<n;i++)
-
for(j=0;j<n;j++)
-
{
-
printf("\n weight of arc %d %d", i,j);
-
scanf("%d",&wt);
-
jointwt(c,i,j,wt);
-
}
-
printf("\n");
-
}
-
// end of function
-
mat(struct arc a[][10], int n)
-
// function to print the weight in matrx
-
{
-
int i,j;
-
printf("\n\t");
-
for(i=0;i<n;i++)
-
{
-
for(j=0;j<n;j++)
-
{
-
printf("%d",a[i][j].wt);
-
}
-
printf("\n\t");
-
}
-
} //end of mat
-
shortpath(int wt, int s, int t, int proced, int n)
-
struct arc wt[][10];
-
int s,t,proced[10];
-
int n;
-
{
-
int dist[10], perm[10];
-
int curr, i,k,dc,h=0;
-
int smalldist, newdist;
-
for(i=0;i<n;i++)
-
{
-
perm[i] = nonmember;
-
dist[i] =infinity;
-
}
-
perm[s] = member;
-
dist[s] = 0;
-
curr = s;
-
while(curr != t)
-
{
-
smalldist = infinity;
-
dc = dist[curr];
-
for(i=0;i<n;i++)
-
if(perm[i] == nonmember)
-
{
-
newdist = dc + wt[curr][i].wt;
-
if(newdist<smalldist)
-
{
-
dist[i] = newdist;
-
proced[i] = curr;
-
}
-
if(dist[i]<smalldist)
-
{
-
smalldist = dist[i];
-
k=i;
-
}
-
}
-
curr = k;
-
perm[curr] = member;
-
path[h++] = curr;
-
}
-
printf("\n\t path is = %d", s+1);
-
for(i=0;i<h;i++)
-
printf("-> %d",path[i]+1);
-
return(dist[t]);
-
} // end of short path
-
/*int cost(struct arc , int );
-
int mat(struct arc , int );
-
void jointwt(struct arc , int , int ,int );
-
int shortpath(int , int , int , int , int );*/
-
int main()
-
{
-
struct arc c[10][10];
-
int n,s,t,proced[10];
-
int x;
-
printf("\n\t\t How many nodes :");
-
scanf("%d",&n);
-
printf("\n\t\t Enter the adjacency matrix of weight");
-
printf("\n\t\t Enter 999 if no edge exits :");
-
cost(c,n);
-
printf("\n\t\t Weight matrix :");
-
mat(c,n);
-
printf("\n\t\t Enter source and distnation :");
-
scanf("%d %d",&s, &t);
-
printf("\n\t\t shortest path from %d to %d is:\n",s,t);
-
x = shortpath(c, s - 1, t - 1, proced, n);
-
} //efmain
7 3144
Does the code compile and run correctly then? Better tell us a specific problem rather than ask us to look for errors in your code.
gpraghuram 1,275
Recognized Expert Top Contributor
Usually shortest distance will be computed with help of Graphs.
You should start from there.
raghu
Banfa 9,065
Recognized Expert Moderator Expert
Perhaps you could list the specific compiler errors you do not understand.
Does the code compile and run correctly then? Better tell us a specific problem rather than ask us to look for errors in your code.
errors in codes are
ISO C++ forbids declaration of `cost' with no type
shortestpath.c: 38: error: ISO C++ forbids declaration of `mat' with no type
shortestpath.c: 51: error: expected constructor, destructor, or type conversion before "struct"
shortestpath.c: 51: error: expected `,' or `;' before "struct"
shortestpath.c: 54: error: expected unqualified-id before '{' token
shortestpath.c: 54: error: expected `,' or `;' before '{' token
shortestpath.c: In function `int main()':
shortestpath.c: 113: error: `shortpath' undeclared (first use this function)
shortestpath.c: 113: error: (Each undeclared identifier is reported only once for each function it appears in.)
Perhaps you could list the specific compiler errors you do not understand.
errors are:-
forbids declaration of `cost' with no type
shortestpath.c: 38: error: ISO C++ forbids declaration of `mat' with no type
shortestpath.c: 51: error: expected constructor, destructor, or type conversion before "struct"
shortestpath.c: 51: error: expected `,' or `;' before "struct"
shortestpath.c: 54: error: expected unqualified-id before '{' token
shortestpath.c: 54: error: expected `,' or `;' before '{' token
shortestpath.c: In function `int main()':
shortestpath.c: 113: error: `shortpath' undeclared (first use this function)
shortestpath.c: 113: error: (Each undeclared identifier is reported only once for each function it appears in.)
Usually shortest distance will be computed with help of Graphs.
You should start from there.
raghu
That depends what is meant by "shortest distance". If the OP means "the least distance connecting N points with straight lines" then you use graph theory (i.e. calculate the minimum spanning tree or work out the Steiner tree problem if you can add intermediate points). If it's just the shortest distance between two points along some cost function then you don't need graph theory, the problem can be solved numerically using Dijkstra's algorithm.
Banfa 9,065
Recognized Expert Moderator Expert
errors are:-
forbids declaration of `cost' with no type
shortestpath.c: 38: error: ISO C++ forbids declaration of `mat' with no type
shortestpath.c: 51: error: expected constructor, destructor, or type conversion before "struct"
shortestpath.c: 51: error: expected `,' or `;' before "struct"
shortestpath.c: 54: error: expected unqualified-id before '{' token
shortestpath.c: 54: error: expected `,' or `;' before '{' token
shortestpath.c: In function `int main()':
shortestpath.c: 113: error: `shortpath' undeclared (first use this function)
shortestpath.c: 113: error: (Each undeclared identifier is reported only once for each function it appears in.)
Now take each error in turn and examine the line of code given and the line of code before that error. For instance
shortestpath.c: 38: error: ISO C++ forbids declaration of `mat' with no type
Line 38 is the definition of you function mat, do you see anything wrong with how you have defined mat?
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Greg Yasko |
last post by:
Hi. Does anyone know if there's an equivalent of Perl's file::find
module in Python? It traverses a directory. I've googled extensively and
checked this newsgroup and can't find anything like it for Python.
I'd be using it in Linux to regularly search for files with a script. Is
this a good application for Python or does Perl have more functionality
for quick & simple scripting in Linux?
Thanks.
|
by: Ethel Aardvark |
last post by:
I am running a 9.0.1 database on a W2K server and have come across
some strange behaviour with a SQL query.
I have a query which runs in a PL/SQL cursor which has several PL/SQL
variables used to switch on and off certain rules. One idea I had was
to have two queries UNIONed together with a simple switch selecting
which half was to operate (I know it sounds like there are probably
better ways of doing this but I have my reasons).
To cut...
|
by: PÃ¥l Eilertsen |
last post by:
Hi,
I have recently installed Visual Studio .Net 2003 and am trying to compile
and run a simple windows form app (used the VS wizard). When trying to run I
get an error message telling me: "fatal error C1083: Cannot open include
file: 'stdlib.h': No such file or directory". I have browsed to C:\Program
Files\Microsoft Visual Studio .NET 2003\Vc7\include and have found the file
there.
What can be wrong? I have also tried to uninstall...
|
by: citizenkahn |
last post by:
I am trying to parse a build log for errors. I figure I can do this
one of three ways:
- find the absolute platonic form of an error and search for that item
- create definitions of what patterns describe errors for each tool
which is used (ant, MSDEV, etc).
- rework the build such that all the return codes for all 3rd party are
captured and logged using my own error description
The return code method has a high level of effort...
|
by: Ben |
last post by:
Hi
We have a list of file paths and short file names in our database.
We need to loop through them all, picking up the long file name from the
file itself and check that the long file name does not include a "~"
character.
I have the short file name and path in a variable (eg
"c:\data\123442~1.doc") how can I get the long file name from this data.
| |
by: priyanka |
last post by:
Hi,
I was wondering if we could parse or do something in the executable(
whose source language was C). How can I use some scripting language
like perl/python to find out the information about the executable ? Is
it possible ?
Also, how does the compiler add inling to the program ? I know that
whenever it sees"inline" in front of the procedure name, it inlines it.
But if we give the -finline options, it inline all the procedures ? How
|
by: CapCity |
last post by:
If I have a strig that represents a path, how can I programmatically get the
"short" DOS name for it?
For example, if I have "C:\Program Files\" I want "C:\Progra~1\".
Thanks
|
by: Alan Cohen |
last post by:
This seems like a really, really dumb question, but I can't seem to find
the simple answer that it seems to deserve.
My C#/ASP.net 2.0 app needs to email a URL link back to the site from a
web page. Sending the email is no problem, but generating this URL is
giving me an annoying issue in testing because of the difference in URLs
between the VS web server and IIS.
Specifically, the URL that I need to send when testing locally (VS...
|
by: Alexander Vasilevsky |
last post by:
Here, there is a challenge: to find the files must be on a local computer,
have the same names.
Get drives and folders to go through without problems. But what and how to
store files while a search?
http://www.alvas.net - Audio tools for C# and VB.Net developers + Christmas
gift
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |