码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 算法学习笔记


    插入排序

    1. #include <iostream>
    2. #define SIZE 10
    3. void insert(int list[], int size);
    4. int list_size[SIZE] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    5. using namespace std;
    6. int main()
    7. {
    8. insert(list_size, SIZE);
    9. cout << endl;
    10. return 0;
    11. }
    12. void insert(int list[], int size) {
    13. int key = 0;
    14. int i = 0, j = 0, count = 0;
    15. for(j = 1; j < size; j++) {
    16. key = list[j];
    17. for(i = j - 1; i >= 0 && list[i] > key; i--, count++){
    18. list[i + 1] = list[i];
    19. }
    20. list[i + 1] = key;
    21. }
    22. for(int k = 0; k < size; k++) {
    23. cout << " " << list[k];
    24. }
    25. cout << endl << "loop count: " << count;
    26. }

    递归查最大值

    1. #include <iostream>
    2. using namespace std;
    3. #define MAX(x,y) \
    4. x > y ? x : y;
    5. int mArray[] = {1,4,2,5,22,545,52,42,545,45,3,45,24,47,2,54,781,2,453,42,45,33,42,20,456,454,352,4,24111,234,5,13,435,165,35,435,435,435,435,1,43,6,13,434,3,4};
    6. int findMax(int *array, int size) {
    7. cout <<"Array:" << array <<"findMax size:" << size << endl;
    8. if(size == 2) {
    9. return MAX(array[0], array[1])
    10. } else if (size == 1) {
    11. return array[0];
    12. } else {
    13. return MAX(findMax(&array[0], size/2), findMax(&array[size/2 + 1], size - (size/2 + 1)));
    14. }
    15. }
    16. int main() {
    17. int max = 0;
    18. int size = sizeof(mArray)/sizeof(int);
    19. max = findMax(mArray, size);
    20. cout << "max: " << max << " size:" << size << endl;
    21. return 1;
    22. }


     

  • 相关阅读:
    腾讯云服务器按量付费如何转为包年包月?
    CSDN客诉周报第6期|本周解决25个用户问题,修复1个漏洞,收到4条建议
    12月2日:thinkphp中的链式操作
    Qt中显示摄像头数据(V4L2三)
    Linux配置strongSwan
    Harbor中镜像清理
    UI5 Tooling
    spark入门--单词统计
    爬虫常见风控
    基于java+SpringBoot+HTML+Mysql项目缺陷管理系统(软件测试管理)
  • 原文地址:https://blog.csdn.net/shanbl_linux_android/article/details/125623723
  • 最新文章
  • 沪漂五周年了:我越来越迷茫了
    Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
    MySQL-Seconds_behind_master的精度误差
    [MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
    AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
    Agent OS :五种驯服不确定性的范式
    PortSwigger SQL注入LAB11
    数据库即时编译JIT
    [Begin]AI Learn Data Day 0
    深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号