|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- #include <iostream>
- #include <cstring>
- using namespace std;
- const int N = 7; // ͼÖнڵãÊýÄ¿
- const int M = 100; // ͼÖбߵÄ×î´óÊýÁ¿
- int h[N]; // ½ÚµãµÄÁÚ½ÓÁ´±íµÄÍ·Ö¸Õë
- int e[M]; // ±ßµÄÖÕµã
- int nex[M]; // ÿһÌõ±ßµÄÏÂÒ»Ìõ±ßµÄ±àºÅ
- int idx = 0; // ±ßË÷Òý
- void add(int a, int b) {
- e[idx] = b;
- nex[idx] = h[a];
- h[a] = idx;
- idx++;
- }
- int main() {
- memset(h, -1, sizeof(h)); // ³õʼ»¯ÁÚ½Ó±íΪ¿Õ
- // Ìí¼Ó±ß
- add(1, 2);
- add(1, 5);
- add(1, 3);
- add(2, 3);
- add(3, 4);
- add(4, 5);
- add(5, 1);
-
- cout << "챐: " ;
- for (int i=0;i<N;i++)
- {
- cout<< i << " ";
-
- }
- cout << endl;
-
- cout << "h: " ;
- for (int i=0;i<N;i++)
- {
- cout<< h[i] << " ";
-
- }
- cout << endl;
- cout << "e: " ;
- for (int i=0;i<N;i++)
- {
- cout<< e[i] << " ";
-
- }
- cout << endl;
-
- cout << "nex: ";
- for (int i=0;i<N;i++)
- {
- cout<< nex[i] << " ";
-
- }
- // // ´òÓ¡ÁÚ½Ó±í
- // for (int i = 1; i <= N; i++) {
- // cout << "h[" << i << "] -> ";
- // for (int j = h[i]; j != -1; j = nex[j]) {
- // cout << e[j] << " -> ";
- // }
- // cout << endl;
- // }
- return 0;
- }
复制代码
h和e我基本明白了,但是nex还是不理解 |
|