File tree Expand file tree Collapse file tree 5 files changed +57
-3
lines changed
Expand file tree Collapse file tree 5 files changed +57
-3
lines changed Original file line number Diff line number Diff line change 1414 * [ 搜索] ( )
1515 * [ 字符串] ( )
1616 * [ 向量/矩阵] ( )
17- * [ 随机] ( )
18- * [ 贪心] ( )
19- * [ 动态规划] ( )
17+ * [ 随机] ( basic/algo/Random.md )
18+ * [ 贪心] ( basic/algo/Greedy.md )
19+ * [ 动态规划] ( basic/algo/DP.md )
2020 * [ 体系结构与操作系统] ( basic/arch/README.md )
2121 * [ 体系结构基础] ( basic/arch/Arch.md )
2222 * [ 操作系统基础] ( basic/arch/OS.md )
Original file line number Diff line number Diff line change 1+ ## 动态规划
2+
3+ 建议观看MIT[ 算法导论-动态规划] ( http://open.163.com/movie/2010/12/L/4/M6UTT5U0I_M6V2U1HL4.html ) 中的课程。
4+
Original file line number Diff line number Diff line change 1+ ## 贪心算法
2+
3+ 建议观看MIT[ 算法导论-贪心算法] ( http://open.163.com/movie/2010/12/1/S/M6UTT5U0I_M6V2U3R1S.html ) 中的课程。
Original file line number Diff line number Diff line change 1+ 链表是一种非常常见的数据结构,主要的在于可以利用非连续的内存以充分利用计算机内存空间,实现灵活的内存动态管理。
2+
3+ ## 单向链表
4+
5+ ``` cpp
6+
7+ ```
Original file line number Diff line number Diff line change 1+ ## 洗牌算法
2+
3+ 洗牌算法,顾名思义,就是只利用一次循环等概率的取到不同的元素(牌)。
4+
5+ 如果元素存在于数组中,即可将每次 random 到的元素 与 最后一个元素进行交换,然后 count--,即可。
6+
7+ 这相当于把这个元素删除,代码如下:
8+
9+ ``` cpp
10+ #include < iostream>
11+ #include < ctime>
12+ using namespace std ;
13+
14+ const int maxn = 10 ;
15+
16+ int a[maxn];
17+
18+ int randomInt (int a) {
19+ return rand()%a;
20+ }
21+ void swapTwoElement(int* x,int* y) {
22+ int temp;
23+ temp=* x;
24+ * x=* y;
25+ * y=temp;
26+ }
27+
28+ int main(){
29+ int count = sizeof(a)/sizeof(int);
30+ int count_b = count;
31+ srand((unsigned)time(NULL));
32+ for (int i = 0; i < count; ++i) { a[ i] = i; }
33+ for (int i = 0; i < count_b; ++i) {
34+ int random = randomInt(count);
35+ cout<<a[ random] <<" ";
36+ swapTwoElement(&a[ random] ,&a[ count-1] );
37+ count--;
38+ }
39+ }
40+ ```
You can’t perform that action at this time.
0 commit comments