欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
圖遍歷應用
圖遍歷應用



#include <stdlib.h>
#define MAXQUEUE 70              

struct node                      
{
   int vertex;                   
   struct node *nextnode;        
};
typedef struct node *graph;      
struct node head[61];             
int visited[61];                  

int queue[MAXQUEUE];             
int front = -1;                  
int rear = -1;                   




void creategraph(int *node,int num)
{
   graph newnode;                
   graph ptr;
   int from;                     
   int to;                       
   int i;

   for ( i = 0; i < num; i++ )   
   {
      from = node[i*2];          
      to = node[i*2+1];          
     
      newnode = ( graph ) malloc(sizeof(struct node));
      newnode->vertex = to;      
      newnode->nextnode = NULL;  
      ptr = &(head[from]);       
      while ( ptr->nextnode != NULL )
         ptr = ptr->nextnode;        
      ptr->nextnode = newnode;       
   }
}




int enqueue(int value)
{
   if ( rear >= MAXQUEUE )       
      return -1;                 
   rear++;                       
   queue[rear] = value;          
}




int dequeue()
{
   if ( front  == rear )         
      return -1;                 
   front++;                      
   return queue[front];          
}




void bfs(int current)
{
   graph ptr;

  
   enqueue(current);             
   visited[current] = 1;         
   printf("[%d]     ",current);  
   while ( front != rear )       
   {
      current = dequeue();       
      ptr = head[current].nextnode;  
      while ( ptr != NULL )          
      {
         if ( visited[ptr->vertex] == 0 )
         {
            enqueue(ptr->vertex);    
            visited[ptr->vertex] = 1;
           
     printf("[%d]    ",ptr->vertex);
         }
         ptr = ptr->nextnode;    
      }
   }
}




void dfs(int current)
{
   graph ptr;

   visited[current] = 1;         
   printf("[%d]    ",current);  
   ptr = head[current].nextnode; 
   while ( ptr != NULL )         
   {
      if ( visited[ptr->vertex] == 0 ) 
         dfs(ptr->vertex);             
      ptr = ptr->nextnode;             
   }
}

 




void main()
{clrscr();

while(1)
{
   char c,a;
   graph ptr;
   int i;
   int node[60][2] = { {1, 10}, {10, 1}, 
         {2, 10}, {10, 2},
         {2, 3}, {3, 2},
         {3, 4}, {4, 3},
         {3, 12}, {12, 3},
         {4, 13}, {13, 4},
         {4, 5}, {5, 4},
         {5, 6}, {6, 5},
         {5, 7}, {7, 5},
         {7, 8}, {8, 7},
         {9, 10}, {10, 9},
         {10, 11}, {11, 10},
         {11, 14}, {14, 11},
         {11, 12}, {12, 11},
         {12, 15}, {15, 12},
         {12, 13}, {13, 12},
         {13, 16}, {16, 13},
         {14, 17}, {17, 14},
         {14, 18}, {18, 14},
         {15, 19}, {19, 15},
         {16, 20}, {20, 16},
         {17, 18}, {18, 17},
         {18, 23}, {23, 18},
         {18, 19}, {19, 18},
         {19, 23}, {23, 19},
         {19, 24}, {24, 19},
         {19, 20}, {20, 19},
         {20, 21}, {21, 20},
         {22, 23}, {23, 22},
         {24, 25}, {25,24}
         };
clrscr();
printf("\n\n\n");
printf("\n");
printf("\n");
printf("\n");
printf("      本 程 序 是 有 關(guān) 圖 的 遍 歷 的 算 法 演示,\n");
printf("如 果 有 不 足 之 處 敬 請 原 諒!\n\n");
printf("請 問(wèn) 你 是 否 要 運 行 以 下 的 程序:\n\n");
printf("   圖 的 深 度 遍歷 和 廣 度 遍 歷? Y/N?\n");
c=getch();
if(c!='y'&&'Y')
exit(0);
 clrscr();

printf("\n\n");
printf("請 注 意 以 下 為 各 城 市 的 代 碼:\n\n");

printf("1:烏魯木齊; 2:呼和浩特; 3:北京; 4:天津; 5:沈陽(yáng); \n");
printf("6:大連; 7:長(cháng)春; 8:哈爾濱; 9:西寧; 10:蘭州;\n");
printf("11:西安; 12:鄭州; 13:徐州; 14:成都; 15:武漢; \n");
printf("16:上海; 17:昆明; 18:貴陽(yáng); 19:株州; 20:南昌;\n");
printf("21:福州; 22:南寧; 23:柳州; 24:廣州; 25:深圳.\n");

   for (i=1;i<=25;i++ )
   {
      head[i].vertex=i;        
      head[i].nextnode=NULL;   
      visited[i]=0;            
   }
   creategraph(node,60);         
   printf("圖 形 的 鄰 接鏈 表 內 容:\n");
   for (i=1;i<=25;i++)
   if(i%3==0)printf("\n");
      printf("頂點(diǎn)%d=>",head[i].vertex);
      ptr=head[i].nextnode;            
      while(ptr!=NULL)      
      {
  printf("%d  ",ptr->vertex); 
  ptr=ptr->nextnode;        
      }
   }
printf("\n\n");
printf("請 選 擇 你 需 要 的 操 作\n");
printf("1、圖形的廣度優(yōu)先遍歷請輸入:'g'或'G'\n");
printf("2、圖形的深度優(yōu)先遍歷請輸入:'s'或'S'\n");
 c=getch();
  switch(c)
{
  case'g':case'G':
   printf("\n請 你 輸 入 你需 要 的 起 始 頂 點(diǎn):\n");
   scanf("%d",&i);
   clrscr();
   printf("\n\n");
   printf("請 注 意 以 下為 各 城 市 的 代 碼:\n\n");
   printf("1:烏魯木齊; 2:呼和浩特; 3:北京; 4:天津; 5:沈陽(yáng); \n");
   printf("6:大連; 7:長(cháng)春; 8:哈爾濱; 9:西寧; 10:蘭州;\n");
   printf("11:西安; 12:鄭州; 13:徐州; 14:成都; 15:武漢; \n");
   printf("16:上海; 17:昆明; 18:貴陽(yáng); 19:株州; 20:南昌;\n");
   printf("21:福州; 22:南寧; 23:柳州; 24:廣州; 25:深圳.\n");

   printf("圖  形  的  廣  度  優(yōu)  先  遍  歷  的  頂  點(diǎn)  內  容:\n");
   bfs(i);                       
   printf("\n");    
   break;
 case's':case'S':
    printf("\n請 輸 入 你 需 要 的 起 始 頂 點(diǎn):\n");
    scanf("%d",&i);
    clrscr();
   printf("\n\n");
    printf("請注 意 以 下 為 各 城 市 的 代 碼:\n\n");
    printf("1:烏魯木齊; 2:呼和浩特; 3:北京; 4:天津; 5:沈陽(yáng); \n");
    printf("6:大連; 7:長(cháng)春; 8:哈爾濱; 9:西寧; 10:蘭州;\n");
    printf("11:西安; 12:鄭州; 13:徐州; 14:成都; 15:武漢; \n");
    printf("16:上海; 17:昆明; 18:貴陽(yáng); 19:株州; 20:南昌;\n");
    printf("21:福州; 22:南寧; 23:柳州; 24:廣州; 25:深圳.\n");

    printf("圖  形  的  深  度  優(yōu)  先  遍  歷  的  頂  點(diǎn)  內  容:\n");
    dfs(i);                       
    printf("\n");                 
     break;
}
printf("\n請 問(wèn) 你 是 否 要 繼 續:y/n");
a=getch();
if(a!='y'&&'Y')
exit(0);
}
}

本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
Java 數組到 HashMap 之算法解釋
圖的廣度優(yōu)先搜索(鄰接表)
C語(yǔ)言難點(diǎn)分析整理
經(jīng)典程序100例(71-80)
C/C++面試題大匯總6
二叉樹(shù)的遍歷
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久