
C语言
西境的小狮子
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
武大国软系统及程序设计 名词解释简答
常考:memory hierarchy:通过多种存储技术使得系统的存储访问能够同时保持速度和容量的保证Hot spot:热点,程序代码中,对计算机cpu执行占据时间比例最大的部分(通常以函数为单位),通过寻找hotspot能够改善程序性能局部性原理:程序倾向于引用临近于其他最近引用过的数据项的数据项,或者最近用过的数据项本身,这种倾向性 按照数据对象存储在存储器中的顺序,以步长为1的引用模式来读取原创 2017-07-23 10:27:57 · 477 阅读 · 0 评论 -
杨辉三角(pascal's triangle)
输入行数,输出对应的杨辉三角本题所用: C(n,0)=1 C(n,k)=C(n,k-1)*(n-k+1)/k运行结果如下: //输入行数,输出对应的杨辉三角 #include <iostream> #include <cstdlib> #include <vector> using namespace std;int main() { int n; std::cin >> n;原创 2017-09-10 19:33:28 · 737 阅读 · 0 评论 -
priority_queue简单用法
#include <fstream> #include <cstdio> #include <string> #include <algorithm> #include <vector> #include <cstdlib> using namespace std;#define max_char_num 10typedef struct treeNode { int freq; c原创 2017-09-09 22:18:17 · 430 阅读 · 0 评论 -
优先队列实现哈夫曼编码(贪心法)
构造哈夫曼树及输出哈夫曼编码,优先队列构造最小堆实现 Windows下输入结束方法:Enter,Ctrl+Z,Enter运行结果如下: #include <fstream> #include <iostream> #include <queue> #include <algorithm> #include <string> using namespace std;typedef struct t原创 2017-09-10 12:16:59 · 3226 阅读 · 0 评论 -
矩阵倒置
矩阵转置#include <stdio.h> #include <malloc.h> #pragma warning(disable:4996)int main() { FILE * fin; FILE * fout; fin = fopen("matrixIn.txt", "r"); fout = fopen("matrixOut.txt", "w"); int原创 2017-09-09 01:50:44 · 1744 阅读 · 0 评论 -
判断是否是素数
判断至i^2<=n时即可 1既不是合数也不是素数#include <cstdlib> #include <iostream> #include <cmath> using namespace std; //判断是否是素数 bool isPrimer(int n) { if (n <= 1) return false; int m = floor(sqrt(n) +原创 2017-09-09 01:48:09 · 391 阅读 · 0 评论 -
8种内排序算法(C++实现)
几种基于比较的内排序,C++简单实现,采用array或vector记录序列,升序排列。插入排序:直接插入排序,折半插入排序,希尔排序 交换排序:冒泡排序,快速排序 选择排序:简单选择排序,堆排序(最大堆) 归并排序(二路) /*以一维数组作为待排序文件的组织形式,并假定关键字均为整数,按递增次序讨论排序算法*/ #include <iostream> #include <vector> usi原创 2017-09-07 00:42:34 · 445 阅读 · 0 评论 -
<algorithm>中的sort()函数
迭代器iterator begin()返回一个iterator 它指向容器的第一个元素 end()返回一个iterator 它指向容器的末元素的下一个位置sort函数:前两个参数是两个指针(记为分别指向元素a和元素b),最后一个参数是一个比较函数,默认比较函数返回值为真时,将a到b之间的数从小到大排列;前两个参数为[a,b),即包含元素a,不包含元素b #include <iostream> #原创 2017-09-09 00:52:18 · 609 阅读 · 2 评论 -
进制转换
10进制转2进制,并统计结果中0的个数与1的个数 使用栈实现#include <iostream> #include <stack> #include <string> #include <vector> using namespace std;void change(int n) { stack<int> s; vector<int> v; int temp; s原创 2017-09-09 01:18:17 · 226 阅读 · 0 评论 -
由遍历序列构造二叉树
根据前序中序确定二叉树 根据后序中序确定二叉树 根据层次中序确定二叉树 注意,根据前序和后序无法确定一棵二叉树 #include <iostream> #include <stack> #include <queue> #include <string> #include <cstdlib> #include <fstream> using namespace std;#define ElemTy原创 2017-09-08 01:33:21 · 1265 阅读 · 0 评论 -
头插法实现链表倒置
首先创建带有头结点的单链表,输入999时,结束//链表倒置 #include <stdio.h> #include <malloc.h>typedef struct LNode { LNode * Next; int data; } LNode,* linkList;//头插法创建链表,输入999时结束,先输入的数据出现在后面 linkList createList(linkList原创 2017-09-06 22:43:40 · 1155 阅读 · 0 评论 -
SSD6 Exercise0: 函数指针数组的使用实例
程序用途:提示使用者输入两个数字,然后进行简单的计算(加减乘除和平方)#include <stdio.h> #include <stdlib.h> #include <math.h>double Add(double x,double y){return x+y;} double Sub(double x,double y){return x-y;} double Mul(double x,doub原创 2017-07-25 23:12:38 · 301 阅读 · 0 评论 -
SSD6 Exercise 1: Decoding Lab
Secret messages: From: CTE To: You Excellent!You got everything!Secret keys: key1:1 key2:777 key3:-1 key4:55系统及所用工具: Win10 gcc+gdb(MinGW32)解题步骤:1.分析extract_message1(start, stride)方法 由于控制台输出原创 2017-07-25 23:51:48 · 1334 阅读 · 0 评论 -
SSD6 Exercise 2: Data Lab(Manipulating Bits)
解题思路: bitAnd(x,y) 根据逻辑学基本知识易得 bitOr(x,y) 根据逻辑学基本知识易得 isZero(x) !x操作符只会返回0(x不为0时)或1(x=0时),符合题目要求 minusOne(void) -1的补码表示是:0xFFFFFFFF,其对应的取反数为0x00000000,刚好为0,故为~0 tmax(void) 0x80二进制表示即1000 0000,又因为32原创 2017-08-02 23:31:43 · 1179 阅读 · 1 评论 -
C语言的一些复杂类型声明
一些比较复杂的声明实例(C Primer Plus中的例子) 数组后面的[]和函数名后面的()具有相同的优先级,它们比*的优先级高。 都是从左往右结合。int board[8][8];; int ** ptr; //一个指向指针的指针,每个元素都是一个指向int的指针 int * risk[10]; //内含10个元素的数组,每个元素都是一个指向int的指针 int (* rusks)[1原创 2017-07-23 21:05:07 · 1031 阅读 · 0 评论 -
树的递归与非递归遍历(C++读文件)
从“tree.in”文件里读取字符串,构造树,若遇到’0’,则认为是空树,然后对该树进行四种遍历#include <iostream> #include <stack> #include <queue> #include <string> #include <cstdlib> #include <fstream> using namespace std;#define ElemType charty原创 2017-09-08 00:16:35 · 461 阅读 · 0 评论