Breadth-first and depth-first searches I searched the net for some bfs and dfs code but rarely found some as reference. I wrote this for an assignment, I am getting the results fine. I want to make my code more compact and remove unwanted stuff or need suggestions to make the code better. I used stack and queue data structures for the implementation
#include &lt;stdio.h&gt;
#include&lt;stdlib.h&gt;
#include &lt;stdbool.h&gt;
#include &lt;string.h&gt;
int F=-1,R=-1;char q[10];
char v[10],check[10];int a[100][100];char stack[10];int top=-1;
char vertex;int pos[10];int s;char Dfsv[10]; int u=9;
int n=0;
int dequeue(){
  if(F==-1)
  {
    printf(&quot;underflow\n&quot;);
  }
  else{
        vertex=q[F];
        printf(&quot;%c&quot;,vertex);
         F++;
         if(F&lt;10)
        { return pos[F];}
        else{ return -1;}
}
}

void insert(int j){
  if(R==9)
  {
    printf(&quot;overflow\n&quot;);
  }
  else if(F==-1&amp;&amp;R==-1)
  {  F++;R++;
    check[j]='v';
      vertex=v[j];
      q[R]=vertex;
  }
  else{ if(check[j]!='v')
          { check[j]='v';R++;
            vertex=v[j];pos[R]=j;

            q[R]=vertex;}
  }
}
void BFS(int s){

 int k=s;


  while(k!=-1)
    {
           for(int j=0;j&lt;n;j++)
            {
               if(a[k][j]==1)
               {
                insert(j);


                }
             }
    k=dequeue();
  }
}
void PUSH(int j){
  if(top==9)
  {
    printf(&quot;overflow\n&quot;);
  }
  else{ if(check[j]!='v')
          { check[j]='v';top++;
            vertex=v[j];pos[top]=j;

            stack[top]=vertex;

  }
}}
int POP(){
  if (top==-1)
  {
    printf(&quot;underflow\n&quot;);
  }
  else{  Dfsv[u]=stack[top];

          top--;u--;
        if(top!=-1)
       { return pos[top+1];}
       else{ return -1;}

  }
}

void DFS(int s){
 int k=s;
  while(k!=-1)
    {
           for(int j=0;j&lt;n;j++)
            {
               if(a[k][j]==1)
               {
                PUSH(j);


                }
             }
    k=POP();
  }
}
void BDFST(){
printf(&quot;enter source number\n&quot;);
scanf(&quot;%d&quot;,&amp;s );
vertex=v[s];insert(s);

printf(&quot;BFS: &quot;);BFS(s);printf(&quot;\nDFS: &quot;);
memset(check, 0, 10);
PUSH(s);
DFS(s);
for(int u=0;u&lt;10;u++)
{
  printf(&quot;%c&quot;,Dfsv[u] );
}
}


void print(int a[100][100],int n,char v[])
{ int j=0;
  for(int i=0;i&lt;n;i++)
  {
     for(j=0;j&lt;n;j++)
     { printf(&quot;%c%c[%d][%d]: &quot;,v[i],v[j],i,j);
       printf(&quot;%d\t&quot;,a[i][j]);
     }
  printf(&quot;\n&quot;);
  }
}

void main(){
int i=0,j=0;
  printf(&quot;enter number of vertex\n&quot;);
  scanf(&quot;%d&quot;,&amp;n);
    printf(&quot;enter vertex's\n&quot;);
     scanf(&quot;%s&quot;,&amp;v);

  printf(&quot;enter the edges\n&quot;);
  for( i=0;i&lt;n;i++)
  {  printf(&quot;enter 1 for edges of %c\n&quot;,v[i]);
     for(j=0;j&lt;n;j++)
     {
       printf(&quot;%c%c[%d][%d]: &quot;,v[i],v[j],i,j);
       scanf(&quot;%d&quot;,&amp;a[i][j] );
      printf(&quot;\n&quot;);
     }
     printf(&quot;\n&quot;);
  }
    print(a,n,v);

    BDFST();



}

```
Welcome to the Code Review Community.
General Observations
The use of small functions is very good and makes the code more readable, but overall the readability can be improved.
The code does seem to follow the concept of the single responsibility principle.
I'm going to address the code in 2 phases, one is dealing with improving the use of C programming and the second is coding style in general.
The use of structures to represent the queues and the stacks might have decreased the complexity of the code.
For the future it might be good if you provided an example input and expected output.
C Programming Improvements
Check for Warnings
When you initially compile with C use the -Wall compiler flag to list any warnings as well as any errors. In many cases the warnings can indicate possible bugs in the code.
While this code compiles it does have the following warnings using the -Wall flag:
gcc -Wall dfsbfs.c
dfsbfs.c:133:6: warning: return type of ‘main’ is not ‘int’ [-Wmain]
  133 | void main(){
      |      ^~~~
dfsbfs.c: In function ‘main’:
dfsbfs.c:138:14: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[10]’ [-Wformat=]
  138 |      scanf(&quot;%s&quot;,&amp;v);
      |             ~^  ~~
      |              |  |
      |              |  char (*)[10]
      |              char *
dfsbfs.c: In function ‘dequeue’:
dfsbfs.c:22:1: warning: control reaches end of non-void function [-Wreturn-type]
   22 | }
      | ^
dfsbfs.c: In function ‘POP’:
dfsbfs.c:87:1: warning: control reaches end of non-void function [-Wreturn-type]
   87 | }
      | ^

The warning about control reaches end of non-void function indicates that the code is missing a return statement if F == -1 in the function dequeue().
The warning about main () indicates that this program is not following the C programming standards about the main() function which should always return an integer value indicating the success or failure of the program to the operating system.
Avoid Global Variables
It is very difficult to read, write, debug and maintain programs that use global variables. Global variables can be modified by any function within the program and therefore require each function to be examined before making changes in the code. In C and C++ global variables impact the namespace and they can cause linking errors if they are defined in multiple files. The answers in this stackoverflow question provide a fuller explanation.
Magic Numbers
There are many Magic Numbers in the global declarations (-1, 10, 100 and 9), it might be better to create symbolic constants for them to make the code more readable and easier to maintain. These numbers may be used in many places and being able to change them by editing only one line makes maintenance easier.
Numeric constants in code are sometimes referred to as Magic Numbers, because there is no obvious meaning for them. There is a discussion of this on stackoverflow.
Readability and Coding Style
Code Consistency
The indentation of the code is inconsistent. This makes the code much harder to read and maintain. For instance it would be better if the function dequeue() looked something like this:
int dequeue(){
  if (F == -1)
  {
    printf(&quot;underflow\n&quot;);
  }
  else{
    vertex = q[F];
    printf(&quot;%c&quot;, vertex);
    F++;
    if (F &lt; 10)
    {
      return pos[F];
    }
    else
    {
      return -1;
    }
  }
}

Some other inconsistencies are that variables are both upper and lower case characters and in most cases are single characters while in some other cases meaningful names. In the C programming language some common practices are that variable and function names are all lower case, and that variable and functions names with multiple words are snake_case. Symbolic constants, which are not used in this program are all upper case.
Horizontal and Vertical Spacing
In most programming languages it is common to improve readability by using horizontal spacing between operators and operands as shown above in the if statements and the printf statements.
The code might be slightly more readable of the open braces { lined up with the closing braces '}', however, this would be determined by local coding standards.