![](https://img-blog.csdnimg.cn/20201014180756738.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
c/c++
ljwy1234
111
展开
-
c++ STL 练习
#define _CRT_SECURE_NO_WARNINGS#include<iostream>using namespace std;#include<string>#include<vector>#include<deque>#include<ctime>#include<algorithm>#include <iomanip>#include<stdlib.h>#include<.原创 2020-08-06 18:03:39 · 419 阅读 · 0 评论 -
c++stl练习
#define _CRT_SECURE_NO_WARNINGS#include<iostream>using namespace std;#include<string>#include<vector>#include<deque>#include<ctime>#include<algorithm>#include <iomanip>#include<stdlib.h>#include<.原创 2020-08-03 16:14:25 · 174 阅读 · 0 评论 -
类模板自定义数组
test.cpp#pragma once#include "MyArr.hpp"#include <string>using namespace std;class Person{public: Person(){ } Person(int a, string n){ this->age = a; this->name = n; } int age; string name;};//输出int数组void print_int(My原创 2020-07-26 17:24:40 · 240 阅读 · 0 评论 -
选择排序
#include<iostream>using namespace std;#include<string>template<class T>void mySwap(T &a, T &b){ T tmp; tmp = a; a = b; b = tmp;}template<class T>void xuanze(T arr[], int len){ for (int i = 0; i < len; .原创 2020-07-22 18:22:32 · 110 阅读 · 0 评论 -
c++实现字符串
mystring.h#define _CRT_SECURE_NO_WARNINGS#pragma once#include <iostream>using namespace std;class mystring{ friend ostream& operator<<(ostream& cout, mystring &str); friend istream& operator>>(istream& cin原创 2020-07-11 18:05:58 · 194 阅读 · 0 评论 -
单例模式
#define _CRT_SECURE_NO_WARNINGS#include <iostream>using namespace std;#include <string>class singleman{public: static singleman* getInstance() { return sman; }private: singleman() { cout << "jkd" << endl; } singl.原创 2020-06-29 17:40:13 · 137 阅读 · 0 评论 -
插入排序
#define _CRT_SECURE_NO_WARNGINGS#include<stdio.h>#include<stdlib.h>#include<string.h>void pirntArray(int arr[], int len){ for (int i = 0; i < len; i++) { printf("%d ", arr[i]); } printf("\n");}//无序序列的左侧是有序序列void char.原创 2020-06-09 18:03:05 · 128 阅读 · 0 评论 -
二叉树层级打印(分层次和不分层次)
需要用到队列queue.h#pragma once#include <stdio.h>#include <stdlib.h>#include <string.h>#ifdef __cplusplusextern "C"{#endif struct queuenode { struct queuenode *next; }; struct lqueue { struct queuenode header;//头结点 in...原创 2020-06-09 13:36:03 · 416 阅读 · 0 评论 -
二叉树完整操作
linkstack.h#pragma once#include<stdio.h>#include<string.h>#include<stdlib.h>#ifdef __cplusplusextern "C"{#endif struct stacknode{ struct stacknode *next; }; struct lstack{ struct stacknode header; int size; }; typed原创 2020-06-08 19:55:20 · 183 阅读 · 0 评论 -
二叉树的基本遍历
#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<string.h>#include<stdlib.h>struct BinNode{ char ch; struct BinNode *lchlid; struct BinNode *rchlid;};//先序遍历 根左右void xianxubianli(struct BinNode *root){ if (NULL == .原创 2020-06-07 11:22:12 · 262 阅读 · 0 评论 -
队列的实现
queue.h#pragma once#include <stdio.h>#include <stdlib.h>#include <string.h>#ifdef __cplusplusextern "C"{#endif struct queuenode { struct queuenode *next; }; struct lqueue { struct queuenode header;//头结点 int size; s原创 2020-06-05 10:29:54 · 107 阅读 · 0 评论 -
单链表
linklist.h#pragma once#include<stdio.h>#include<string.h>#include<stdlib.h>#ifdef __cplusplusextern "C"{#endif typedef void * lianbiao; typedef void(*Foreach)(void *); typedef int(*compare)(void *, void *); //初始化链表 lianb原创 2020-05-25 14:18:56 · 113 阅读 · 0 评论 -
选择排序
int arr[] = { 2, 4, 7, 1, 9, 8 }; for (int i = 0; i < sizeof(arr) / sizeof(arr[0]); i++) { int min = i; for (int j = i + 1; j < sizeof(arr) / sizeof(arr[0]); j++) { if (arr[j] < a...原创 2020-05-07 17:44:11 · 153 阅读 · 0 评论 -
链表复习
#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<stdlib.h>#include<string.h>#include<time.h>//链表的结点类型定义struct LinkNode{ int data; struct LinkNode *next;}...原创 2020-05-06 09:43:09 · 185 阅读 · 1 评论 -
指针复习
#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<stdlib.h>#include<string.h>#include<time.h>char *my_strs(const char *str, const char *substr){ const char *...原创 2020-04-21 14:18:16 · 130 阅读 · 0 评论 -
c语言结构体复习
#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<stdlib.h>#include<string.h>#include<time.h>struct students{ char name[21]; unsigned int age; char tel[16];...原创 2020-04-06 17:48:34 · 295 阅读 · 0 评论 -
字符串排序
#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<stdlib.h>#include<string.h>#include<time.h>void paixu(char **arr,int len){ for (int i = 0; i < len - 1; ...原创 2020-03-25 18:44:32 · 193 阅读 · 0 评论 -
stract的实现
#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<stdlib.h>#include<string.h>#include<time.h>char *my_stract(char *arr, char *s1){ char *sb = arr; while ...原创 2020-03-25 14:33:56 · 1740 阅读 · 0 评论 -
strstr的实现
#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<stdlib.h>#include<string.h>#include<time.h>char *my_strstr(char *dest, char *src){ int i = 0; int j = 0;...原创 2020-03-24 17:20:40 · 140 阅读 · 0 评论 -
C语言去除字符串空格
void quchukongge(char p[]){ char *q; while (*p != '\0'){ if (*p == ' '){ q = p + 1; while (*q != '\0') { if (*q != ' ') { //空格和非空格调换位置 避免数据重复 *p = *q; *q = ' ...原创 2020-03-23 17:26:23 · 815 阅读 · 1 评论 -
指针冒泡排序 从小到大
#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<stdlib.h>#include<string.h>#include<time.h>void kedou(int arr[], int len){ for (int i = 0; i < len - 1;...原创 2020-03-20 17:02:19 · 532 阅读 · 0 评论 -
c语言合并2个字符串
#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<stdlib.h>#include<string.h>#include<time.h>int main(void){ char a[] = "jian"; char b[] = "kedou"; int le...原创 2020-03-12 15:32:33 · 3798 阅读 · 0 评论 -
随机生成指定个数学生的语文数学外语成绩并求平均值
#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<stdlib.h>#include<string.h>#include<time.h>int main(void){ srand((unsigned int)time(NULL)); //int num = ra...原创 2020-03-12 13:21:13 · 1323 阅读 · 0 评论 -
冒泡排序从小到大
#include<stdio.h>#include<stdlib.h>#include<string.h>#include<time.h>int main(void){ srand((unsigned int)time(NULL)); printf("请输入生成的数组个数\n"); int count; scanf("%d"...原创 2020-03-11 13:41:56 · 210 阅读 · 0 评论 -
输出正反等腰三角形(菱形)
#include<stdio.h>#include<stdlib.h>int main(void){ int i,j,k,num; printf("请输入要出现猩猩的行数 输出正反三角形:"); scanf("%d",&num); for (i=1;i<=num;i++) ...原创 2020-03-10 16:55:52 · 316 阅读 · 0 评论 -
c 去除字符串2边的空格
#include #include int main(){ char str[] = " are u ok? "; char tmp[100]; int n = strlen(str); char * start = &str[0]; char * end = &str[n-1]; while( *start == ' ') {转载 2018-01-11 10:20:03 · 318 阅读 · 0 评论 -
c统计查找的字符串个数
#define _CRT_SECURE_NO_WARNINGS#include #include #include int main(){ //char str[1024] = "abcdhahaefghhaha,ijklhaha"; char *str = "abcdhahaefghha\ha,ijklha\ha"; char *p; int num=0; //方法一原创 2018-01-11 10:57:17 · 2590 阅读 · 0 评论 -
atoi的实现和 字符指针数组
1、不用使用库函数,编写一个函数my_atoi(),功能和atoi是一样的int my_atoi(char *str);my_atoi("+123"); 结果为十进制123my_atoi("-123"); 结果为十进制-123my_atoi("123"); 结果为十进制123提示:字符如何转换为整形:'1' - '0' = 1; '2' - '0' = 2;转载 2018-01-11 11:33:12 · 775 阅读 · 0 评论 -
c语言 static变量和函数
static int a = 2; //1、static只能在本文件使用此变量//2、每个文件可以定义一个static全局变量//3、static没有声明,只有定义,只有定义往后的代码才能使用#include static int a = 2; //1、static只能在本文件使用此变量//2、每个文件可以定义一个static全局变量//3、static没有声明,只有定义,只有转载 2018-01-11 15:16:25 · 257 阅读 · 0 评论 -
memset 和 memcpy 和 memcmp (strncmp遇到\0会中断)
int main(){ int a; //memset的作用用于给一段内存清0 memset(&a, 0, sizeof(a)); // 0000 0001 0000 0001 0000 0001 0000 0001 memset(&a, 1, sizeof(a)); //给每一个字节设置指定的数 printf("a = %d\n", a); int b[100]; mems转载 2018-01-11 16:07:45 · 2285 阅读 · 0 评论 -
malloc和free
free后地址不会改变 除非赋值为NULL这样活着赋值其他的堆空间地址#define _CRT_SECURE_NO_WARNINGS#include #include #include int main(){ int * p; p = (int *)malloc(sizeof(int)); if (NULL == p) { printf("err\n"); retu原创 2018-01-11 16:30:21 · 99 阅读 · 0 评论 -
c语言函数里开辟堆空间问题
#define _CRT_SECURE_NO_WARNINGS#include #include #include #include #include void func(int **p){ int *temp; temp= (int *)malloc(sizeof(int)); *temp = 100; *p = temp; printf("func %d\n",原创 2018-01-11 17:13:30 · 2916 阅读 · 0 评论 -
结构体套1级指针
#include #include #include //声明一个结构体类型,它是类型,不是变量struct Student{ int score; char *name; int age;}; //这里有分号,这是语法int main(){ struct Student * p; int n = 3; int i; //指向堆区数组, struct Studen转载 2018-01-11 20:00:24 · 230 阅读 · 0 评论 -
结构体与联合体区别
#include #include struct A{ unsigned char a; unsigned short b; unsigned int c;};union B{ unsigned char a; unsigned short b; unsigned int c;};int main(){ //1、结构体大小为所有成员相加,联合体大小为最大成员的转载 2018-01-11 20:30:03 · 261 阅读 · 0 评论 -
c语言枚举
#include #include /*#define Empty 0#define Black 1#define White 2*/enum ChessStatus //枚举类型{ //成员不定定义变量,是写标示符 //默认从0开始,后一个比前一个大1 Empty, Black=1, White //枚举成员,枚举常量};int main(){ //定义枚举变转载 2018-01-11 20:31:59 · 208 阅读 · 0 评论 -
文件操作相关
1、产生500个100以内的随机数,以如下格式写入文件中(每写一个数字后换行):102030提示:fputs(),sprintf()#include #include #include #define MAX 500void write_file(){ FILE *fp = NULL; //以写方式打开文件 fp = fopen("./test.txt", "转载 2018-01-12 09:44:06 · 130 阅读 · 0 评论 -
文件拷贝相关
#include #include int main(int n, char **p){ if(n != 3) { printf("use err: ./a.out src dst\n"); return -1; } printf("%s, %s\n", p[1], p[2]); if( strcmp(p[1], p[2]) == 0) { printf("源文件转载 2018-01-12 09:44:26 · 126 阅读 · 0 评论 -
指针
int main(void){ int a[10]; //a, 和 &a数据类型不一样 //a, 首元素地址,首元素是int, 首元素地址是int *, int * 指向int, +1, +sizeof(int) //&a, 整个数组的地址,整个数组是int [10], +1, +sizeof(int [10]) printf("a = %d, &a = %d\n", a, &a);转载 2018-01-12 15:18:25 · 117 阅读 · 0 评论 -
c语言const
#define _CRT_SECURE_NO_WARNINGS#include#include#include//const int a = 10; //errint main(void){ //1、const修饰普通局部变量,只读变量(假的常量),通过指针间接修改 //2、const修饰全局变量, static变量,是真正的常量 //static const int a转载 2018-01-12 15:27:30 · 144 阅读 · 0 评论 -
malloc calloc realloc
calloc#define _CRT_SECURE_NO_WARNINGS#include#include#includeint main(void){ //指针,指向堆区空间,5个int类型 //指向首元素,首元素是int, 需要int * int * p; int n = 5; p = (int *)malloc(n * sizeof(int)); //内存的值为随机数转载 2018-01-12 16:34:09 · 114 阅读 · 0 评论