- 博客(23)
- 收藏
- 关注
原创 文件操作总结
文件可分为文本文件和二进制文件od -tx1 -tc -Ax 文件名 读二进制文件文本文件特点:存储量大,转换为二进制速度慢,直观易记二进制文件特点:存储量小,无需转换。但因一个字节不对应一个字符,故不能直接输出其字符形式打开文件FILE *这样的指针称为不透明指针(Opaque Pointer)或者叫句柄(Handle)。
2024-03-06 20:43:26 958
原创 指针小陷阱
其实这两就是一个意思,函数调用的时候把数组名给了另一个指针变量。(数组名不能当左值,数组名就是一个地址,而指针则是一个左值)如果不标记旧地址,返回str意味着指向最后一位的地址。先将字符串的地址标记,然后改变里面的值,返回地址。
2024-03-06 20:35:18 194
原创 【数据结构】排序算法总结
每趟将一个待排序的关键字按照其值的大小插入到已经排好的部分有序序列的适当位置上,直到所有待排关键字都被插入到有序序列中为止。:最坏情况为O(n²) 最好情况为O(n) 平均情况为O(n²):O(1)
2024-03-06 20:33:59 723
原创 c++结构体练习
#include #include <string.h>using namespace std;class Person{public:void initPerson(const char *name, const int age);void setName(const char *name);void setAge(int age);void display();...
2019-09-14 10:21:28 430
原创 静态栈(数组)
#include <stdio.h>#define STACK_SIZE 12int stack[STACK_SIZE];int top = 0;int is_full(){return top == STACK_SIZE;}void push(int data) //压栈{if (!is_full()){stack[top++] = data;...
2019-08-16 11:29:44 167
原创 约瑟夫环,数组方法。
#include <stdio.h>#include <stdlib.h>int *init(int n) //数组初始化{int i;int *people = (int *)malloc(n * sizeof(int));if (people == NULL){ printf...
2019-08-15 20:03:40 180
原创 约瑟夫环,链表方法。
#include <stdio.h>#include <stdlib.h>typedef struct node{int item;struct node *next;}node;node *head = NULL;node *mk_node(int item){node *p = (node *)malloc(sizeof(node));if (p ...
2019-08-15 20:01:28 100
原创 单链表(头节点)
#include <stdio.h>#include <stdlib.h>typedef struct node{int item;struct node *next;}node;node sentry = {0, NULL}; //头节点(哨兵)node *head = &sentry;node *mk_node(...
2019-08-06 13:11:52 161
原创 第一次写链表(头指针)
#include <stdio.h>#include <stdlib.h>typedef struct node{int item;struct node *next;}node;node *head = NULL;node *mk_node(int item){node *p = (node *)malloc(sizeof(node));if (p ...
2019-08-02 18:26:17 158
原创 位操作练习
#include <stdio.h>void print_array(unsigned int x) //以二进制打印出32位整形数.{int i;unsigned int mask = 1u;for (i = 31; i >= 0; i--){ if ((mask << i) & x) { ...
2019-07-26 15:59:34 114
原创 位操作练习(右移)
#include <stdio.h>void print_array(int x) //以二进制打印出32位整形数{int i;unsigned int mask = 1u;for (i = 31; i >= 0; i--){ if ((mask << i) & x) { printf("1"...
2019-07-25 18:59:04 222
原创 冒泡排序,二分法查找(递归和迭代),选择排序,插入排序
#include <stdio.h>void swap(int *a, int *b) //交换a和b的值{int temp;temp = *a;*a = *b;*b = temp;}void print_array(int *a, int len) //打印函数{int i;for(i = 0; i < len; i++){ pri...
2019-07-20 10:20:24 149
原创 用*打印菱形。
#include <stdio.h>int get_pattern(int n){int i, j, k; for(i = n - 1; i >= 0; i--) { for(j = 0; j <= i; j++) { printf(" "); } for(k = 1; k <= 2 * (n - i...
2019-07-16 15:51:19 122
原创 统计字母数字空格其他字符的个数。
代码实现。#include <stdio.h>int main(){int num1 = 0;int num2 = 0;int num3 = 0;int num4 = 0;char ch; printf("请输入一段字符:"); while((ch = getchar()) != '\n') { if((ch >= 'a' &&...
2019-07-16 15:46:09 933
原创 求一个三位数,组成它的3个数字阶乘之和正好等于它本身。
#include <stdio.h>int get_magic(int n){int total = 0;int i;int a; while(n > 0) { int b = 1; if(n % 10 == 0) { a = 1; }else { a = n % 10; ...
2019-07-14 20:23:59 1369 1
原创 求完数。
一个数恰好等于它的因子之和。例如:6=1+2+3 请编程找出1000以内的完数。#include <stdio.h>int get_comn(int n){int total = 0;int i; for(i = 1; i < n; i++) { if(n % i == 0) { total = total + i; ...
2019-07-14 20:21:12 942
原创 按4-4/3+4/5-4/7+4/9······来计算π的值,并打印出每一项算出来的值。
#include <stdio.h>#include <math.h>float get_pi(int n){float total = 0.0;int i; for(i = 1; i < n + 1; i++) { total = total + 4.0 * pow(-1, i + 1) / (2.0 * i - 1.0); } ret...
2019-07-14 20:16:41 1216
原创 链表(基础)理解
1 #include <stdio.h>23 typedef struct node4 {5 int item;6 struct node *next;7 }node_t;89 node_t *head = NULL;1011 int main()12 {13 node_t n1 = {1, NULL};14 node_t n2...
2019-05-04 11:44:03 98
原创 数组转置
二维数(3*3方阵)组转置。1 #include <stdio.h>23 void reverse(int a[3][3])4 {5 int i;6 int j;7 int tmp;89 for(i = 0;i <= 2;i++)10 {11 for(j = i + 1;j <= 2; j++)...
2019-05-03 17:01:44 512
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人