C 一个非递减数组 下标从0到n 元素的取值范围为从0到n的整数 判断其中是否有重复元素

分享一下我老师大神的人工智能教程!零基础,通俗易懂!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.*/
           

给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow
这里写图片描述
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值