This is BFS code
C Code:
  1. /*
  2.  *      BFS.c
  3.  *      
  4.  *      Copyright 2008 Pham Duy Tung <spider@spider-laptop>
  5.  *      
  6.  *      This program is free software; you can redistribute it and/or modify
  7.  *      it under the terms of the GNU General Public License as published by
  8.  *      the Free Software Foundation; either version 2 of the License, or
  9.  *      (at your option) any later version.
  10.  *      
  11.  *      This program is distributed in the hope that it will be useful,
  12.  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  *      GNU General Public License for more details.
  15.  *      
  16.  *      You should have received a copy of the GNU General Public License
  17.  *      along with this program; if not, write to the Free Software
  18.  *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  19.  *      MA 02110-1301, USA.
  20.  */
  21.  
  22.  
  23. #include <stdio.h>
  24. int QUEUE[100],chuaxet[100],a[100][100],count=0,n,thu_tu[100];
  25. void BFS(int v);
  26. void tham_dinh(int v);
  27. int main()
  28. {
  29.     int i,j;
  30.     printf("\n nhập số đỉnh");
  31.     scanf("%d",&n);
  32.     printf("\n nhập ma trận KỀ(nhớ là ma trân kề dấy)");
  33.     for(i=1;i<=n;i++));
  34.  
  35.     for(j=1;j<=n;j++)
  36.     {
  37.         printf("\n a%d%d=",i,j);
  38.         scanf("%d",&a[i][j]);
  39.     }
  40.    
  41.     for(i=1;i<=n;i++)   chuaxet[i]=1;
  42.     for(i=1;i<=n;i++)
  43.     if(chuaxet[i]) BFS(i);
  44.    
  45.     printf("\n Dinh          So thu tu duoc tham");
  46.     for(i=1;i<=n;i++)
  47.     printf("\n %-20d%d",i,thu_tu[i]);
  48.     return 0;
  49. }
  50. void BFS(int v)
  51. {
  52.     int dau,cuoi,i,u;
  53.     dau=1; cuoi=1;
  54.     QUEUE[cuoi]=v;
  55.     chuaxet[v]=0;
  56.     while(dau<=cuoi)
  57.     {
  58.         u=QUEUE[cuoi];
  59.         dau=dau+1;
  60.         tham_dinh(u);
  61.         for(i=0;i<=n;i++)
  62.         if(a[u][i]&&chuaxet[i])
  63.         {
  64.             cuoi=cuoi+1;
  65.             QUEUE[cuoi]=i;
  66.             chuaxet[i]=0;
  67.         }
  68.     }
  69. }
  70. void tham_dinh(int v)
  71. {
  72.     count++;
  73.     thu_tu[v]=count;
  74. }

and this is DFS code:
C Code:
  1. /*
  2.  *      DFS.c
  3.  *      
  4.  *      Copyright 2008 Pham Duy Tung <spider@spider-laptop>
  5.  *      
  6.  *      This program is free software; you can redistribute it and/or modify
  7.  *      it under the terms of the GNU General Public License as published by
  8.  *      the Free Software Foundation; either version 2 of the License, or
  9.  *      (at your option) any later version.
  10.  *      
  11.  *      This program is distributed in the hope that it will be useful,
  12.  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  *      GNU General Public License for more details.
  15.  *      
  16.  *      You should have received a copy of the GNU General Public License
  17.  *      along with this program; if not, write to the Free Software
  18.  *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  19.  *      MA 02110-1301, USA.
  20.  */
  21.  
  22.  
  23. #include <stdio.h>
  24. int chuaxet[100],a[100][100],thu_tu[100],count=0,n;
  25. void DFS(int v);
  26. void tham_dinh(int v);
  27. int main()
  28. {
  29.     int i,j;
  30.     printf("\n nhap so dinh cua do thi\n");
  31.     scanf("%d",&n);
  32.     printf("\n nhap ma tran ke:");
  33.    
  34.     for(i=1;i<=n;i++)
  35.     for(j=1;j<=n;j++)
  36.     {
  37.         printf("\n a%d%d=",i,j);
  38.         scanf("%d",&a[i][j]);
  39.     }
  40.  
  41.     for(i=1;i<=n;i++) chuaxet[i]=1;
  42.     for(i=1;i<=n;i++)
  43.     if(chuaxet[i])
  44.     {
  45.         DFS(i);
  46.     }
  47.     printf("\n Dinh          So thu tu duoc tham");
  48.     for(i=1;i<=n;i++)
  49.     printf("\n %-20d%d",i,thu_tu[i]);
  50.     return 0;
  51. }
  52.  
  53. void DFS(int v)
  54. {
  55.     int i;
  56.     tham_dinh(v);
  57.     chuaxet[v]=0;
  58.     for(i=1;i<=n;i++)
  59.     {
  60.         if((a[v][i]==1)&&(chuaxet[i]==1))
  61.         {
  62.             DFS(i);
  63.         }
  64.        
  65.     }
  66. }
  67. void tham_dinh(int v)
  68. {
  69.     count++;
  70.     thu_tu[v]=count;
  71. }