## 2010年10月25日 星期一

### [ 資料結構 小學堂 ] 圖形結構 : 圖形的追蹤

1. #include
2.
3. using namespace std;
4.
5. class graphicPoint{
6. public:
7.     int val;
8.     class graphicPoint *next;
9.     graphicPoint(){
10.         next = NULL;
11.         val = -1;
12.     }
13. };
14.
15. int run[6] = {0};
16. class graphicPoint head[6]; // 共有5個頂點
17. void dfs(int current) {
18.     graphicPoint *ptr;
19.     run[current] = 1;
20.     cout << "[" << current << "] ";
22.     while(ptr!=NULL) {
23.         if(run[ptr->val]==0)
24.             dfs(ptr->val);
25.         ptr = ptr->next;
26.     }
27. }
28. void main(bool b) {
29.     if(b) {
30.         int data[14][2] = {{1,2}, {2,1}, {1,5}, {5,1}, {2,3}, {3,2}, {2,4}, {4,2}, {3,4}, {4,3}, {3,5}, {5,3}, {4,5}, {5,4}}; //圖形邊線陣列宣告
31.         for(int i=0; i<14; i++) {
32.             int tmpi = data[i][0];
33.             int tmpj = data[i][1];
34.             graphicPoint *npt = new graphicPoint;
35.             npt->val = tmpj;
37.             while(pt->next != NULL)
38.                 pt = pt->next;
39.             pt->next = npt;
40.         }
41.         cout << "圖形鄰接串列內容 : " << endl;
42.         for(int i=1; i<6; i++) {
44.             cout << "頂點 " << i << "=>";
45.             while(pt!=NULL)  {
46.                 cout << "[" << pt->val << "] ";
47.                 pt  = pt->next;
48.             }
49.             cout << endl;
50.         }
51.         cout << "深度優先走訪頂點 :" << endl;
52.         for(int i=0; i<6; i++) { // 初始化run 陣列
53.             run[i] = 0;
54.         }
55.         dfs(1);  // 以頂點1為起點
56.         printf("\n");
57.     }
58. }

[1] [2] [3] [4] [5]

[ 資料結構 小學堂 ] 圖形結構 : 圖形表示法

### [ Python 文章收集 ] List Comprehensions and Generator Expressions

Source From  Here   Preface   Do you know the difference between the following syntax?  view plain copy to clipboard print ? [x  for ...