![](https://img-blog.csdnimg.cn/20201014180756926.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法-c语言实现
学习学习学习ing
这个作者很懒,什么都没留下…
展开
-
判断单链表是否有环
问题一判断单链表是否有环:建立两个指针,一个fast,一个slow,fast每次走两步,slow每次走一步,如果有环他们就会相遇,如果没有环,就会伴随fast遇到NULL而结束。 代码如下:#include<stdio.h> typedef struct Node { int val; Node *next; }Node, *pNode; //判断是否有环 bool isLoop(原创 2017-03-18 11:15:27 · 354 阅读 · 0 评论 -
需要记住的一些知识
一,二叉树: Theorem 1: The number of leaves in a non-empty full binary tree is one more than the number of internal nodes. Theorem 2: The number of null pointers in a non-empty binary tree is one mo原创 2017-03-21 20:43:21 · 203 阅读 · 0 评论 -
算法实现
容斥原理给定a1, a2, a3 , … ,am, 求1到n的整数中至少能整除a中一个元素的数有几个?#include<stdio.h> #define MAX_M 8 typedef long long ll; int a[MAX_M]; int n, m;int gcd(int a, int b) { if (b) while ((a %= b) && (b %= a)); re原创 2017-03-13 10:18:48 · 350 阅读 · 0 评论 -
活用各种数据结构
排序算法一, 代价为(n^2)的排序算法: 1,插入排序:template<typename E> void swap(E A[], int first, int second) { E temp = A[first]; A[first] = A[second]; A[second] = temp; } template<typename E> bool prior(E a原创 2017-03-15 19:35:57 · 238 阅读 · 0 评论