By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,204 Members | 1,161 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,204 IT Pros & Developers. It's quick & easy.

Expression syntax in function

P: 1
while compiling this program it gives a syntax error saying "expression syntax in function add" in line no. 96. Kindly help.
#include<stdio.h>
int q[20],top=-1,front=-1,rear=-1,a[20][20],vis[20],stack[20];
int delete();
void add(int item);
void bfs(int n,int s);
void dfs(int n,int s);
void push(int item);
int pop();
main()
{
int n,i,s,ch,j;
char c,dummy;
printf("\nenter the number of vertices:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
printf("\enter 1 if %d has a node with %d else o:",j,i);
scanf("%d",a[i][j]);
}
}
printf("\nthe adjacency matrix is:");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
printf("\n%d",a[i][j]);
}
printf("\n");
}
do
{
for(i=1;i<=n;i++)
vis[i]=0;
printf("MENU");
printf("\n1.B.F.S");
printf("\n2.D.F.S");
printf("\nenter your choice:");
scanf("%d",&ch);
printf("\nenter the source vertex:");
scanf("%d",&s);
switch(ch)
{
case 1:bfs(s,n);
break;
case 2:dfs(s,n);
break;
}
printf("\ndo you want to continue(Y/N)?");
scanf("%d",&dummy);
scanf("%c",&c);
}
while((c=='y')||(c=='Y'));
}
void bfs(int s,int n)
{
int p,i;
add(s);
vis[s]=1;
p=delete();
if(p!=0)
printf("\n%d");
while(p!=0)
{
for(i=1;i<=n;i++)
if((a[p][i]!=0)||(vis[i]==0))
{
add(i);
vis[i]=1;
}
p=delete();
if(p!=0)
printf("\n%d",p);
}
for(i=1;i<=n;i++)
if(vis[i]==0)
bfs(i,n);
}
void add(int item)
{
if(rear==19)
printf("\nqueue full");
else
{
if(rear==-1)
{
q[++rear]=item;
front++;
}
else
{
q[++rear]=item;
}
}
int delete()
{
int k;
if((front>rear)||(front==-1))
return(0);
else
{
k=q[front++];
return(k);
}
}
void dfs(int n,int s)
{
int k;
push(s);
vis[i]=1;
k=pop();
if(k!=0)
printf("\n%d",k);
while(k!=0)
{
for(i=1;i<=n;i++)
if((a[k][i]!=0))||(vis[i]==0))
{
push(i);
vis[i]=1;
}
k=pop();
if(k!=0)
printf("\n%d",k);
}
for(i=1;i<=n;i++)
if(vis[i]==0)
dfs(i,n);
}
void push(int item)
{
if(top==19)
printf("\nstack overflow");
else
stack[++top]=item;
}
int pop()
{
int k;
if(top==-1)
return(0);
else
{
k=stack[top--];
return(k);
}
}
}
Mar 25 '17 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 2,400
It is hard to tell from this listing but it looks like function add() is missing a closing brace }.

It helps when you enclose your source code in Code tags using the [CODE/] button.
Mar 25 '17 #2

weaknessforcats
Expert Mod 5K+
P: 9,197
This code:

Expand|Select|Wrap|Line Numbers
  1. p = delete();
will never compile because delete is a C++ keyword. You are not allowed to have a function with the same name as a C++ keyword. Therefore, rename your delete function to something else.
Mar 25 '17 #3

Post your reply

Sign in to post your reply or Sign up for a free account.