note

今天刷题,忘了去重复库函数,于是手写了一个。 前提: 必须保证数组是有序的。

源码

template <typename T>
void unique_arr(T arr[], int len, T* parr, int& out_len)
{
if (1 > len || nullptr == parr || NULL == parr)
return; int cur_index = 0;
int pre_index = 0;
int real_len = 1; parr[0] = arr[0]; while (cur_index < len)
{
if (arr[pre_index] != arr[++cur_index])
{
pre_index = cur_index;
parr[real_len++] = arr[cur_index];
}
} out_len = real_len;
}

调用

	int arr2[10] = { 0 };
int real_len = 0; int arr[] = { 5, 1, 3, 2, 3, 4, 4, 2, 1, 6 };
// 排序
std::sort(std::begin(arr), std::end(arr));
// 去重复
unique_arr(arr, 10, arr2, real_len); // 输出
for (int i = 0; i < real_len - 1; ++i)
std::cout << " " << arr2[i];

最新文章

  1. Oracle学习笔记2
  2. userdebug版本开机串口log打开
  3. python - 简明 性能测试
  4. HDOJ/HDU 1073 Online Judge(字符串处理~)
  5. ASE中的主要数据库
  6. Oracle Tablespace Transportation
  7. Python学习笔记:概要
  8. java设计原则---开闭原则
  9. jdbc 链接数据库步骤 7步
  10. Windows苹果安卓手机远程桌面客户端推荐
  11. SpringMVC 与 REST.
  12. SpringMVC学习 十三 拦截器栈
  13. centos7下配置saltstack
  14. java JDBC (八) 连接池 DBCP
  15. sublime配置 sublimecondeintel 分号后不要提示
  16. Python类的构成元素
  17. quartz ? * 区别
  18. [转]cron表达式详解
  19. N76E003之IIC
  20. MYSQL三大范式

热门文章

  1. cat的生产应用
  2. C语言 自定义函数按行读入文件
  3. account, accomplish, accumulate
  4. Linux基础命令---ab测试apache性能
  5. Linux基础命令---vmstat显示虚拟内存状态
  6. Mysql多字段模糊查询
  7. 二、SpringBoot实现上传文件到fastDFS文件服务器
  8. Maven的聚合工程(多模块工程)
  9. 【VSCode】检测到 #include 错误。请更新 includePath。已为此翻译单元(C:\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\i686-
  10. 匿名内部类与lamda表达式