上一页 1 ··· 4 5 6 7 8 9 10 下一页
摘要: 点击查看代码 /* n个皇后放置问题: 在一个n*n的国际象棋棋盘上放置n个皇后,使得这n个皇后两两均不在同一行、同一列、同一条对角线上,求合法的方案数 */ #include<cstdio> #include<cmath> //使用abs() #pragma warning(disable:499 阅读全文
posted @ 2022-09-27 22:51 zhaoo_o 阅读(6) 评论(0) 推荐(0) 编辑
摘要: 点击查看代码 /*输出n个正整数的全排列*/ #include<cstdio> #pragma warning(disable:4996) //允许使用scanf和printf const int maxn = 11; //待排序序列最多11个元素 //P[]为当前排列,HashTable[x]记录 阅读全文
posted @ 2022-09-27 22:48 zhaoo_o 阅读(28) 评论(0) 推荐(0) 编辑
摘要: 点击查看代码 #include<iostream> using namespace std; //结点定义 struct LNode { int data; struct LNode* next; }; /* 函数功能:创建单链表 函数列表: head:指向创建的单链表头结点的指针 a[]:待排序序 阅读全文
posted @ 2022-09-26 22:58 zhaoo_o 阅读(34) 评论(0) 推荐(0) 编辑
摘要: 点击查看代码 #include<algorithm> using namespace std; /* 函数功能:双向冒泡排序(有序排序) 函数列表: a[]:待排序序列 n:待排序元素个数 */ void BubbleSort(int a[], int n) { int left = 0, righ 阅读全文
posted @ 2022-09-26 22:05 zhaoo_o 阅读(6) 评论(0) 推荐(0) 编辑
摘要: 点击查看代码 /* 函数功能:简单计数排序(有序排序)(元素为个位整数,且序列不含有相同值的元素) 函数列表: a[]:待排序序列 n:待排序元素个数 */ void CountSort(int a[], int n) { int* tmp = new int[n]; //暂存排序后的有序序列 in 阅读全文
posted @ 2022-09-26 22:03 zhaoo_o 阅读(1) 评论(0) 推荐(0) 编辑
摘要: 点击查看代码 #include<cstdio> #pragma warning(disable:4996) //桶排序:对元素按照flag(个、十、百位)进行排序 void BucketSort(int a[], int n, int flag) { int* tmp = new int[n]; / 阅读全文
posted @ 2022-09-26 21:57 zhaoo_o 阅读(2) 评论(0) 推荐(0) 编辑
摘要: 点击查看代码 #include<cstdio> #pragma warning(disable:4996) //二路归并排序从上往下(升序排序) //2、二路归并排序:归并 void merge(int a[], int n, int start, int mid, int end) { int* 阅读全文
posted @ 2022-09-26 21:52 zhaoo_o 阅读(5) 评论(0) 推荐(0) 编辑
摘要: 点击查看代码 #include <iostream> using namespace std; /*小顶堆函数降序排序修改: 1、MaxHeap函数中改为if (c < end && a[c] > a[c + 1])//如果有右孩子,则用较小者与父结点进行比较 2、MaxHeap函数中改为if (t 阅读全文
posted @ 2022-09-25 22:33 zhaoo_o 阅读(1) 评论(0) 推荐(0) 编辑
摘要: 点击查看代码 #include<iostream> using namespace std; //简单选择排序(升序排序) void SelectSort(int a[], int n) { //i是有序区末尾位置(在升序排序中,a[i]是有序区的最大元素),j是无序区起始位置,min是最小元素的位 阅读全文
posted @ 2022-09-25 20:37 zhaoo_o 阅读(7) 评论(0) 推荐(0) 编辑
摘要: 点击查看代码 #include<iostream> using namespace std; void Swap(int a[], int i, int j) { //互换a[i]和a[j] int tmp = a[i]; a[i] = a[j]; a[j] = tmp; } int Partiti 阅读全文
posted @ 2022-09-25 15:02 zhaoo_o 阅读(2) 评论(0) 推荐(0) 编辑
上一页 1 ··· 4 5 6 7 8 9 10 下一页