本文目錄一覽:
C語言里抓圖
你的程序必須在前台(點擊你程序的標題欄,或任務欄中你程序的圖標),再按alt+PrintScreen,然後再word中按ctrl+v
C語言實現圖的廣度優先搜索遍歷算法
先寫個大題思路,樓主先自己想想,想不出來的話,2天後給代碼。
queuenode q;
q.push(start);
bool canVisit[][];
node cur;
while(!q.empty()){
cur = q.top();
q.pop();
foreach(node is connected by cur){
if(canVisit[node.x][node.y])
{
printf(“訪問結點(%d,%d)”,node.x,node.y);
canVisit[node.x][node.y]=false;
q.push(node);
}
}
}
急!!如何用C語言建立一個圖和圖的深度優先搜索遍歷,舉個例子就行,要代碼!!謝謝!!
/* ======================================== */
/* 圖形的深度優先搜尋法 */
/* ======================================== */
#include stdlib.h
struct node /* 圖形頂點結構宣告 */
{
int vertex; /* 頂點資料 */
struct node *nextnode; /* 指下一頂點的指標 */
};
typedef struct node *graph; /* 圖形的結構新型態 */
struct node head[9]; /* 圖形頂點結構數組 */
int visited[9]; /* 遍歷記錄數組 */
/* —————————————- */
/* 建立圖形 */
/* —————————————- */
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; /* 插入結尾 */
}
}
/* —————————————- */
/* 圖形的深度優先搜尋法 */
/* —————————————- */
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()
{
graph ptr;
int node[20][2] = { {1, 2}, {2, 1}, /* 邊線數組 */
{1, 3}, {3, 1},
{2, 4}, {4, 2},
{2, 5}, {5, 2},
{3, 6}, {6, 3},
{3, 7}, {7, 3},
{4, 8}, {8, 4},
{5, 8}, {8, 5},
{6, 8}, {8, 6},
{7, 8}, {8, 7} };
int i;
for ( i = 1; i = 8; i++ )
{
head[i].vertex = i; /* 設定頂點值 */
head[i].nextnode = NULL; /* 清除圖形指標 */
visited[i] = 0; /* 設定遍歷初值 */
}
creategraph(node,20); /* 建立圖形 */
printf(“圖形的鄰接鏈表內容:\n”);
for ( i = 1; i = 8; i++ )
{
printf(“頂點%d =”,head[i].vertex); /* 頂點值 */
ptr = head[i].nextnode; /* 頂點位置 */
while ( ptr != NULL ) /* 遍歷至鏈表尾 */
{
printf(” %d “,ptr-vertex); /* 印出頂點內容 */
ptr = ptr-nextnode; /* 下一個頂點 */
}
printf(“\n”); /* 換行 */
}
printf(“圖形的深度優先遍歷內容:\n”);
dfs(1); /* 印出遍歷過程 */
printf(“\n”); /* 換行 */
}
tc語言循環找圖怎麼寫,
空間 依次找圖
整型 線程編號1
功能 邏輯型 線程方法1()
循環(真)
輔助.等待(1000)
鍵盤.按鍵(65,1) //A
輔助.等待(500)
整型 x,y,圖I
圖I=圖像.找圖(0,0,1440,900,”rc:I.bmp”,#102030,0.8,0,x,y) //找圖I
如果(x0)
鍵盤.按鍵(66,1) //B
輔助揣叮編顧妝該表雙勃晶.等待(500)
鍵盤.按鍵(67,1) //C
輔助.等待(500)
整型 x,y,圖II
x = 0 //我不懂你這個語言,用就是在這裡給x賦初值0就是
循環( x = 0) //同樣,改成你這個語言的判斷
圖II=圖像.找圖(0,0,1440,900,”rc:II.bmp”,#102030,0.8,0,x,y) //找圖II
如果(x0)
鍵盤.按鍵(68,1) //D
輔助.等待(500)
如果結束
循環結束
如果結束
循環結束
返回 真
功能結束
原創文章,作者:KEDH,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/141135.html
微信掃一掃
支付寶掃一掃