- 博客(18)
- 收藏
- 关注
原创 实现选择排序
/* * 此程序用于实现选择排序 * 作者:zhy * 时间:2021/7/20 */ #include <stdio.h> #include <stdlib.h> // 用双重循环实现 // 参数array为排序数组首地址,参数len为排序元素个数 void selectsort1(int *array,int len); // 使用递归实现 // 参数array为排序数组首地址,参数len为排序元素个数 void selectsort2(int *array,in
2021-07-30 09:26:48
184
原创 实现基数排序(数组+链表)
/* * 此程序用于实现基数排序 * 作者:zhy * 时间:2021/7/24 */ #include <stdio.h> #include <stdlib.h> #include <string.h> // 用于存放数据的节点 typedef struct inode { int data; struct inode *next; }inode,*pnode; int getcount(int obj); int getnum(int obj,in
2021-07-30 09:23:45
232
原创 实现快速排序
/* * 此程序用于实现快速排序 * 作者:zhy * 时间:2021/7/21 */ #include <stdio.h> #include <stdlib.h> // 递归实现主函数 // 参数:left 左标 right 右标 // 参数:arr 排序数组首地址 void quicksort(int *arr,int left,int right); int main(int argc,char *argv[]) { int arr[]={44,3,38,5,4
2021-07-30 09:22:16
139
原创 归并排序(递归实现)
/* * 此程序用于实现归并排序(递归实现) * 作者:zhy * 时间:2021/7/21 */ #include <stdio.h> #include <stdlib.h> #include <string.h> // 归并排序用递归实现 void mergesort(int *arr,int len); // 递归调用子函数 void _mergesort(int *arr,int *arrtmp,int start,int end); int ma
2021-07-30 09:21:32
171
原创 实现归并排序
/* * 此程序用于实现归并排序 * 作者:zhy * 时间:2021/7/21 */ #include <stdio.h> #include <stdlib.h> #include <string.h> int min(int a,int b); // 归并排序用循环实现 void mergesort1(int *arr,int len); // 归并排序用递归实现 void mergesort2(int *arr,int len); int main
2021-07-30 09:20:34
124
原创 实现插入排序
/* * 此程序用于实现插入排序 * 作者:zhy * 时间:2021/7/21 */ #include <stdio.h> #include <stdlib.h> // 插入排序实现 // 参数 array 排序数组的首地址 // 参数 len 参与排序元素的个数 void insertsort(int *array,int len); int main(int argc,char *argv[]) { int arr[]={44,3,38,5,47,15,36
2021-07-30 09:19:25
94
原创 实现希尔排序
/* * 此程序用于实现希尔排序 * 作者:zhy * 时间:2021/7/21 */ #include <stdio.h> #include <stdlib.h> // 对同一组的元素进行插入排序 // 参数 arr 需要排序的数组首地址 // 参数 span 本次排序各元素位置的跨度 // 参数 len 需要排序的数组长度 void GroupInsertSort(int *arr,int span,int len); // 希尔排序函数 // 参数 arr 需要
2021-07-30 09:18:33
136
原创 实现堆排序
/* * 此程序用于实现堆排序 * 作者:zhy * 时间: 2021/7/22 */ #include <stdio.h> #include <stdlib.h> // 元素交换函数 void swap(int &a,int &b); // 堆排序主函数 // arr : 堆化数列首地址 // len :未排序的元素个数 void heapsort(int *arr,int len); // 堆化函数(循环实现) // arr : 堆化数列首地址
2021-07-30 09:16:03
109
原创 冒泡排序实现
/* 此程序用于实现冒泡排序 * 作者:zhy * 时间:2021/7/20 */ #include <stdio.h> #include <stdlib.h> // 使用双重循环实现 // array是待排序数组的首地址,len参数是需要排序的元素个数 void bubblesort1(int *array,int len); // 使用递归实现(单层递归) // array是待排序数组的首地址,len参数是需要排序的元素个数 void bubblesort2(int
2021-07-30 09:05:48
122
原创 封装信号灯操作并结合共享内存应用
文章目录前言一、信号灯操作类二、操作主函数 前言 本程序皆为进程间通信,若需测试可运行两个相同进程 一、信号灯操作类 // 此类封装了信号灯操作 class CSEM { private: union semun { int val; struct semid_ds *buf; unsigned short *arry; }; int sem_id; // 信号灯描述符 public: bool init(key_t key); // 如果信号灯已存在,获取信号灯;如果信
2021-07-29 17:47:11
171
原创 socket通信多线程的服务端与客户端
文章目录前言一、通信服务端二、通信客户端 前言 本试验是在已实现多进程服务端的基础上(详情可查看我发布的另一个文章),将数据的收发分给交给两个线程完成 一、通信服务端 /* * 此程序用于测试线程级的tcp服务端并发 * 作者:zhy * 日期:2021/4/11 */ #include "_public.h" CTcpServer TcpServer; void EXIT(int sig) { printf("程序退出,信号值:%d\n",sig); close(TcpServer.
2021-07-29 17:20:27
284
原创 对socket通信的封装以及实现服务端的多进程服务
文章目录前言通信服务端服务端main主函数服务端操作类通信客户端客户端main函数客户端操作类 前言 本篇内容是对已实现的通信程序进行模块化封装以及将服务端改为多进程并发通信,将初始化sokcet和recv与send操作封装成类,套接字描述符与通信实现的具体细节对用户隐藏。 通信服务端 服务端main主函数 /* * 此程序演示socket通信服务 * 作者:zhy 时间:2020 4 4 */ #include <stdio.h> #include <sys/socket.h&
2021-07-29 16:47:34
197
原创 简单实现Linux网络通信
文章目录前言一、通信服务端二、通信客户端 前言 本篇内容只实现基础的建立连接与半双工通信功能 一、通信服务端 /* * 此程序测试socket点对点的连接服务端 * 作者:zhy 时间:2020 4 5 */ #include <stdio.h> #include <sys/socket.h> #include <unistd.h> #include <sys/types.h> #include <string.h> #include
2021-07-29 15:42:53
407
原创 关于可变参数的试验
/* * 此程序实验可变参数函数 * 作者:zhy 时间:2020 3 29 */ #include <stdio.h> #include <stdarg.h> #include <string.h> void Printf(const char*,...); void Sprintf(char* str,const char*,...); int main() { char buf[50]; memset(buf,0,sizeof(buf)); P
2021-07-29 15:19:35
102
原创 时间操作(字符串与长整数的转换)
前言 用到的时间操作函数原型: time_t mktime(struct tm *tm); mktime函数用于把struct tm表示的时间转换为time_t表示的时间。 struct tm * localtime(const time_t *); localtime函数用于把time_t表示的时间转换为struct tm结构体表示的时间,函数返回struct tm结构体的地址。 /* * 此程序演示时间操作 * 作者:zhy 时间:2020 1 31 */ #include <.
2021-07-29 15:00:40
554
原创 实现目录相关操作
文章目录前言一、逐级创建目录二、获取目录下的文件二、获取目录及其所有子目录下的文件 前言 对目录的操作有很多,本文只实现最常用的创建目录和获取目录下的文件以及获取目录及其所有子目录下的文件 一、逐级创建目录 /* * 此程序用于测试MKDIR函数 * 作者:zhy 时间:2020 1 30 */ #include <stdio.h> #include <dirent.h> #include <string.h> #include <stdlib.h>
2021-07-29 11:31:19
147
原创 对文件操作的实例应用
文章目录前言一、文件拷贝二、写入和读取数据文件 前言 通过学习文件相关操作,尝试实现文件拷贝和对格式化数据的存取 一、文件拷贝 /* * 此程序用以文件复制 * 作者:zhy 时间:2020 1 22 */ #include <stdio.h> #include <string.h> #include <stdlib.h> int main(int argc,char *argv[]) { if(argc!=3) { printf("\n这是一个文
2021-07-29 10:49:33
172
原创 文件操作学习
日常练习 文章目录日常练习前言一、使用C语言库函数打开关闭文件二、文本文件文件读取与写入三、二进制文件文件读取与写入四、文件其他操作 前言 此部分为C语言在Linux下编程的相关操作 一、使用C语言库函数打开关闭文件 FILE *fopen( const char * filename, const char * mode ); int fclose(FILE *fp); 二、文本文件文件读取与写入 写入文本文件 int fprintf(FILE *fp, const char *format,
2021-07-29 10:18:02
157
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人