ARTICLE DETAIL

资讯详情

深耕网站建设、视觉设计与SEO优化的一线实战洞察。

我的神经元算法

我的神经元算法

一个非常简单的冒泡排序。

这是我人生写下的第一段算法程序,纯凭在脑中实物化指针与数组才有了下面的代码的诞生。

因此有点冗杂。不过,留着以后自己看看吧,那时希望我有别样的体会

#include <stdbool.h>void print_array(int *, int, int);// void sort(int * array, int size)
// {
//     int p;//     for (int a = 0; a < size; a++)
//     {
//         for (int b = 0; b < (size - 1); b++)
//         {
//             if (array[b] < array[b + 1])
//             {
//                 p = array[b];
//                 array[b] = array[b + 1];
//                 array[b + 1] = p;
//             }
//         }
//         print_array(array, size, a);
//     }
// }void sort(int * array, int size)
{// 降序排序函数int p;bool sorting_completed = false;int sorted_number = 0;int index = 0;int count = 0;while (!sorting_completed){if (size > 1){for(index = 0, sorted_number = 0; index < size - 1; index++){if (array[index] < array[index + 1]){p = array[index];array[index] = array[index + 1];array[index + 1] = p;}if (array[size - 1 - index - 1] < array[size - 1 - index]){sorted_number--;}else{sorted_number++;}if (sorted_number == (size - 1)){sorting_completed = true;}}}else{sorting_completed = true;}print_array(array, size, count);count++;}
}
返回列表