- 博客(15)
- 收藏
- 关注
原创 归并、快速、基数和计数排序
归并排序 void merger_arr(int arr[],int left,int right){ int mid = (left+right)/2; //arr[left],arr[mid] arr[mid+1] arr[right] int cnt = mid-left+1; int *brr = calloc(cnt,sizeof(int)); int i; for(i=0;i<cnt;i++){ brr[i] = arr[left+i]; } int j,k; i=left,j=0,
2020-08-22 14:22:51
119
原创 堆排序和插入排序
#include<stdio.h> //堆排序 void reheap(int arr[],size_t n,size_t index){ if(index>=n) return; int key = arr[index]; int child = 2index+1; while(child < n){//子节点存在 if(child+1 < n && arr[child+1]>arr[child]){ ++child; } if(arr[child]&
2020-08-22 14:19:46
307
原创 冒泡排序和选择排序
#include <stdio.h> #include <stdlib.h> void swap(int *pa,int *pb){ int t = *pa; *pa = *pb; *pb = t; } void show(int arr[],size_t n){ int i; for(i=0;i<n;i++){ printf("%d “,arr[i]); } printf(”\n"); } //冒泡排序 void bubble_sort(int arr[],size_t n
2020-08-22 14:16:57
231
原创 数组与二叉树
//数组中的元素是否可能是有序二叉树前序遍历的结果 bool arr_is_prev_btree(T arr[],size_t n){ if(n<=1) return true; //arr[0] 根 if(n==2){ return arr[0]!=arr[1]; } int i=1; int mid = 0; for(i=1;i<n&&arr[i]<arr[0];i++){ } if(i>=n){ return arr_is_prev_btree(arr+1
2020-08-08 10:35:18
329
原创 二叉树的遍历(不使用递归)
//前序遍历 根->左子树->右子树 void btree_foreach_prev2(BTree tree,void (*foreach)(T)){ if(tree == NULL) return; Stack s; stack_init(&s,btree_size(tree)); stack_push(&s,tree); while(!stack_is_empty(&s)){ BNode *node = stack_pop(&s); foreach(node
2020-08-08 10:33:03
393
原创 判断一个单向链表是否有环
typedef int T; //单向链表的节点 typedef struct SNode{ T data; //节点的元素 struct SNode *next; //下一个节点的内存位置 NULL表示后面没有节点了 }SNode; typedef struct SNode * SLink;//SLink 单向链表类型 //单向链表 只需要记住 首节点的内存位置即可 最后一个节点的next不为NULL 而是指向其中一个节点 bool isCircle(SL
2020-08-08 10:16:12
175
原创 单向链表的逆序
typedef int T; //单向链表的节点 typedef struct SNode{ T data; //节点的元素 struct SNode *next; //下一个节点的内存位置 NULL表示后面没有节点了 }SNode; typedef struct SNode * SLink;//SLink 单向链表类型 //单向链表 只需要记住 首节点的内存位置即可 SLink slink_reverse(SLink link){//head if(link
2020-08-08 10:15:10
122
原创 用二叉树排序
#include <stdio.h> //调整index下标节点 void reheap(int arr[],size_t n,int index){ int key = arr[index]; int child = 2index+1; while(child<n){//存在子节点 if(child+1<n && arr[child+1]>arr[child]){ ++child; //取右子节点和左子节点中较大的一个 } if(key<arr[chil
2020-08-08 09:13:34
160
原创 用栈堆进行整数分解
整数分解: 例:6 6=1+1+1+1+1+1 6=1+1+1+1+2 6=1+1+1+3 6=1+1+2+2 6=1+1+4 6=1+2+3 6=1+5 6=2+2+2 6=2+4 6=3+3 #include <stdio.h> #include “stack.h” Stack s; void print(T data){ printf("%d ",data); } //num分解为cnt个整数相加 void reslove_to_count(int num,size_t cnt){ //
2020-08-08 09:12:14
149
原创 胡图图想学c语言6之考点
##4G的内存分布 从低到高: 代码段: 程序运行时加载程序指令到内存中形成4G虚拟内存镜像 存储代码指令 字符串字面值 代码段的内容不能修改 一旦修改必然核心已转储(段错误) 全局静态区-数据段 已初始化的全局变量和静态变量 全局静态区-bss段 未初始化的全局变量和静态变量 全部自动清0 堆(动态内存) 从小到大使用 程序员手动申请 手动释放 堆栈缓冲区(加载的动态库) 使堆栈数据不重叠 栈 从大到小使用 局部变量 形参 块变量 调用函数时的内存开销 程序自己维护 不需要程序员自己操心 自动
2020-07-27 21:05:12
144
原创 胡图图想学c语言5之考点
##自增减运算符 ++(自增1) --(自减1) int x=0,y=0; ++x; y++; 语句运行之后x和y的结果都为1 x=0,y=0; int m=0,n=0; m = ++x; 相当于: x = x+1; m = x; 先自增运算,再计算表达式 n = y++; 相当于: n = y; y = y+1; 先计算表达式,然后再自增 #例: int a = 10; int b = a++ + ++a; //b = 22 a = 12 a = 10; a = a++ + ++a;//
2020-07-23 18:24:08
302
原创 胡图图想学c语言之字符串函数原型
#写函数原型 1.#include <stdio.h> #include <assert.h> size_t mystrlen(const char s){ assert(s!=NULL); size_t len = 0; for(;(s+len)!=’\0’;len++); return len; } int main(){ char *p = “Hello world!\n”; printf("%u\n",mystrlen§); return 0; } 2.#include &
2020-07-18 15:16:42
378
原创 胡图图想学c语言呀3
快速排序:#include <stdio.h> void quickSort(int arr[],size_t left,size_t right){ if(left >= right){ return; } int key = arr[left];//标准key 放在合适的位置 使得左边的元素全部<=key 右边全部的元素>=key int i=left,j=right; while(i<j){ //右边找一个比key小的 while(i<j &&a
2020-07-15 18:09:54
135
原创 胡图图的学习笔记二呀
#第一个星期 ##最大公约数的两种求法 40 96 40 96 40%96=56 96-40=56 56%40=16 56-40=16 40%16=8 40-16=24 8%8=0 2
2020-07-12 23:30:05
240
原创 胡图图的学习日志一呀
开头先提醒自己一句计算机中存储数据以补码的形式存在!!!! 然后今天来算一下float和double的取值范围 float长度为四个字节即有32个二进制位,其中有一个符号位8个指数位23个小数位: 将他的二进制移位得 1.11111…(23个1)*2^ n 因为n为有正负的8个二进制位,所以取n为128-1 1.11111…(23个1)*2^127 =(1+1/2+1/4+18+…+1/2^23 )*2 ^127 =(1+1/2+…+1/2^23 +1/2 ^ 23-1/2 ^ 23)*2 ^127
2020-07-12 21:50:29
181
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人