分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow
也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!
#include <iostream>#define NULL 0using namespace std;int hasDup(int a[], int n){ for(int i = 0; i <= n; ++i) { while(a[i] != i && a[i] != -1) { if(a[a[i]] == -1) { return 1; } a[i] = a[a[i]]; a[a[i]] = -1; } if(a[i] == i) { a[i] = -1; } } return 0;}void main(){ int a[10] = {0, 2, 3, 3, 3, 5, 6, 7, 8, 9}; int result = hasDup(a, 9); if(result == 1) { cout << "The array does HAVE the duplicated nodes." << endl; } else { cout << "The array does NOT HAVE the duplicated nodes." << endl; }}// Output:/*The array does HAVE the duplicated nodes.*/