- 博客(29)
- 收藏
- 关注
原创 优先队列-堆
1.优先队列中出入一个新元素(节点)void Insert(ElementType X,PriorityQueue H){int i;if(IsFull(H)){Error("Priority queue is full");return;}for(i=++H->Size;H->Elements[i/2]>X;i/2)H->Elements[i]=H->Elements[i/2];H->Elements[i]=X;}2.优先队列中取出最小值
2022-01-17 17:54:09
170
1
原创 6种常见的排序
1.冒泡排序#include<stdio.h>#include<string.h>#include<stdlib.h>#include<time.h>#include<sys/timeb.h>#define MAX 10//记录时间函数long getSystemTime(){struct time tb;ftime(&tb);return tb.time*1000+tb.millitm;}//交换函数in
2022-01-17 00:57:12
519
原创 二叉树的#号创造法
#include<stdio.h>#include<string.h>#include<stdlib.h>//二叉树的节点typedef struct BinaryNode(){char ch;struct BINARYNODE*lchild;struct BINARYNODE*rchild;};void Recursion(BinaryNode*root){if(NULL == root){return;}printf("%c",rot.
2022-01-16 19:12:46
343
原创 二叉树的非递归遍历
1.将根节点压入栈中2.进入循环:只要栈中元素个数大于0,进行循环操作2.1弹出栈顶元素2.2如果这个栈顶元素标记为真,输出这个元素并且执行下次循环2.3如果栈顶元素为假,将节点的标志设为真2.4将该节点的右子树、左子树、根压入栈中2.5执行下一次循环#include<stdio.h>#include<string.h>#include<stdlib.h>struct BinaryNode{char ch;struct Binar
2022-01-16 00:31:04
428
原创 二叉树的编程
一.树的遍历二.统计叶子的数量三.求树的高度四.拷贝二叉树五.释放二叉树binaryTree.h#pragma once#include<stdio.h>#include<string>#include<stdlib.h>struct BinaryNode{char ch;//数据域struct BinaryNode* lChild;//左孩子节点struct BinaryNode* rChild;//右孩子节点};//遍
2022-01-15 23:55:23
361
原创 二叉树的递归遍历
先序遍历(根 左 右) 中序遍历(左 根 右) 后续遍历(左 右 根) printf("%c",root->ch) recursion(root->lChild) recursion(root->lChild)recursion(root->lChild) pfrintf("%c",root-...
2022-01-15 23:44:22
70
原创 队列的链式存储实现
对外接口一.初始化队列二.入队三.出队四.返回对头元素五.返回队尾元素六.返回队列大小七.判断队列是否为空八.销毁队列linkQueue.h#pragma once#include<stdio.h>#include<string.h>#include<stdlib.h>//链表节点struct QueueNode{struct QueueNode*next;//只维护指针域};struct LQueue{s
2022-01-15 18:17:43
413
原创 队列的顺序存储实现
一.初始化队列二.入队三.出队四.返回头元素五.返回尾元素六.返回队伍大小七.销毁seqQueue.h(动态数组)#pragma once#include<stdio.h>#include<stdlib.h>#include<string.h>#include"dynamicArray.h"//动态数组的头文件#define MAX 1024#define void* seqQueue;//初始化队列//入列seqQu
2022-01-15 16:35:11
86
原创 就近匹配.
"5+5*(6)+9/3*1)-(1+3("/*从第一个字符开始扫描当遇见普通字符是忽略当遇见左括号时压入栈中当遇见右括号时从栈中弹出栈项符号,并进行匹配匹配成功,继续读入下一个字符匹配失败,立即停止,并报错结束:成功:所有字符扫描完毕,并且为空失败:匹配失败或所有字符扫描完毕但栈非空*/contact.h(上上条博客:栈的顺序存储文件)tset.c#include"contact.h"(我的上上个博客:栈的顺序存储)//判断是否为右括号int IsRight(
2022-01-14 23:02:40
131
原创 栈的链式存储
一.初始化栈二.入栈三.出栈四.获取栈顶元素五.栈的大小六.判断栈是否为空七.销毁栈contacat.h#pragma once#include<stdio.h>#include<string.h>#include<stdlib.h>struct StackNode{struct StackNode*next;//只维护指针域};//链式的栈结构体struct LStack{struct Stack pHeader;
2022-01-14 22:00:16
131
原创 栈的顺序存储
一.初始化栈二.入栈三.出栈四.获取栈顶元素五.栈的大小六.判断栈是否为空七.销毁栈contact.h (头文件)#pragma once#include<stdio.h>#include<string.h>#include<stdlib.h>#define MAX 1024struct SStack{void*data[MAX]//数组int m_Size//元素个数};typedef void*seqStack/
2022-01-14 18:22:15
160
1
原创 单项链表-企业级版本
一#include<stido.h>#include<string.h>#include<stdlib.h>strucrt LinkNode{//只维护指针域struct LinkNode * next;};struct LList{struct LinkNode pHeader;//链表头节点int m_Size;//链表长度};typedef void *LinkList;
2022-01-14 00:37:20
117
原创 单向链表.
一.初始化链表二.插入链表三.遍历链表四.删除链表1.按位删除2.按值删除五.返回链表长度六.清空链表七.销毁链表#include<stdio.h>#include<string.h>#include<stdlib.h>//链表节点struct LinkNode{void * data;//数据域struct LinkNode *next;//指针域};//链表结构体struct LList{struct
2022-01-13 17:17:25
83
原创 动态数组.
一.将元素按指定位置插入数组的功能二.遍历数组的功能三.删除数组中元素的功能1.按指定位置删除数组元素2.按指定的值删除数组元素四.销毁数组的功能头文件(底层开发)#include<stdio.h>include<string.h>#include<stdlib.h>//动态数组结构体struct dynamicArray {void ** pAddr;//维护在堆区真实数组指针int m_capacity;//数组容量in
2022-01-12 23:59:25
141
原创 文件结束判定
1.文本文件读取是否结束,判断返回值是否为EOF(fgetc),或NULL(fgets)例 :fgetc判断是否为EOF。fgets判断返回值是否为NULL。2.二进制文件的读取结束判断,判断返回值是否小于实际要读的个数。例: fread判断返回值是否小于实际要读的个数fgetc/fgets:#include<stdio.h>#include<stdlib.h>int main (){int c;FILE*fp=fopen("tset.txt","
2022-01-11 01:05:44
927
原创 文件的随机读写
fseekint fseek(FILE*stream, long offset,int orign);#include<stdio.h>#include<errno.h>int main (){FILE* pf=fopen("tset.txt","r");if(pf ==NULL){printf("%s\n",strerror(errno));return 0;}//1.定位文件指针fseek(pf,2,SEEK_CUR);//2.读取文件int
2022-01-11 00:09:58
205
原创 文件版通讯录的实现
contach.h(头文件)#include<stdio.h>#include<string.h>#include<stdlib.h>#include<errno.h>//#define MAX 1000# define DEFAULT_SZ 3#define MAX_SEX 5#define MAX_TELE 12#define MAX_ADDR 30enum Option{EXIT,ADD,DEL,SEARCH,MOD
2022-01-10 23:51:18
334
原创 文件的操作
一.文件的打开与关闭#include<stdio.h>#include<errno.h>int main(){//打开文件FILE* pf= fopen("tset.txt","w");if(pf==NULL){printf("%s\n",strerror(errno));return 0;}//关闭文件fclose(pf);pf=NULL;return 0;}二.文件的顺序读写1.int fputc(int c,FILE* st.
2022-01-10 23:09:11
80
原创 动态版通讯录的实现
contach.h#include<stdio.h>#include<string.h>#include<stdlib.h>//#define MAX 1000# define DEFAULT_SZ 3#define MAX_SEX 5#define MAX_TELE 12#define MAX_ADDR 30enum Option{EXIT,ADD,DEL,SEARCH,MODIFY,SHOW,SORT};struct Peo
2022-01-10 16:56:25
176
原创 数组版通信录的实现
contach.h#include<stdio.h>#include<string.h>#define MAX=1000#define MAX_SEX 5#define MAX_TELE 12#define MAX_ADDR 30enum Option{EXIT,ADD,DEL,SEARCH,MODIFY,SHOW,SORT};struct PeoInfo{cahr name[20];int age;char sex[5];char..
2022-01-09 19:18:48
193
原创 常见的动态内存的错误
1对空指针解引用的操作#include<stdio.h>#include<stdlib.h>int main(){int*p=(int*) malloc(10);//未考虑p=NULL;int i= 0;for(i=0;i <5; i++){printf("%d\n",*(p+i));}free(p);p=NULL;}2.对动态开辟的内存的越界访问问题;#include<include.h>#include<stdl
2022-01-08 00:57:52
257
原创 开辟动态内存与释放
#include<stdlib.h>#include<string.h>#include<errno.h>#include<stdio.h>int main (){int*p=(int*)malloc(10*sizeof(int));if(p=NULL){printf("%s",strerror(errno));}else{for(i=0;i<10;i++){*(p+i)=i;}for(i=0;i.
2022-01-07 23:01:11
432
原创 判断当前计算机大小端存储
联合体做法#include<stdio.h>#include<string.h>int check_sys(){union Un{char c;int i;}u;u.i=1;return u.c;}int main(){int a = 1;// 0x01 00 00 00 || 0x00 00 00 01int ret= check_sys();if(1==ret){printf("小端\n");}else{printf("大端\n
2022-01-04 18:15:39
333
原创 字符串函数&内函数使用和剖析(二)
my_memcpy可以处理不重叠的内存拷贝(只能从前向后拷贝)#include<stdio.h>#including<string.h>#include<assert.h>void* my_memcpy (void* dest,const void* src,size_t num){void* ret=dest;assert(dest!=NULL);assert(srt!=NULL);while(num--){*(char*)dest=*(cha
2022-01-04 14:07:25
374
原创 常见字符操作
切割分割符#include<stdio.h>#include<string.h>int main (){char aar[]="zhangy@22.nan";char *p="@.";cahr buf[1024]={0};strcpy(buf,arr);cahr* ret=NULL;for(ret=strtok(arr,p);ret!=NULL;ret=strtok(NULL,p)){printf("%s\n",ret);}return 0;}
2022-01-03 22:54:31
44
原创 字符串函数&内函数使用和剖析(一)
字符串的追加#include<stdio.h>char* my_strcat(char* dest,const char* src){assert(dest!=NULL);assert(src!=NULL);char* ret= dest;while(*dest !=\0){dest++;}while(*dest++=*src++) //my_strcpy{;}}int main(){char arr1[30]="hello";char arr2[]
2022-01-02 18:30:30
181
原创 杨氏矩阵.
有一个数字矩阵,矩阵的每行从左到右是递增的,矩阵从上到下是递增的,请编写程序在这样的矩阵中查找某一个数字是否存在。#include<stdio.h>int FindNum(int arr[3][3],int k,int *px,int *py){int x=0;int y=*py-1;while(x<=*px-1 && y>=0){if(arr[x][y]>k){y--;}else if(arr[x][y]<k){x++;
2022-01-01 23:17:00
111
原创 旋转字符操作
左旋转字符,如abcdef->bcdefa(左旋转一个);abcdef->cdefab#include<string.h>viod left_move(hcar arr[], int k){assert(arr!=NULL);int i=0;intlen=strlen(arr);for(i=0;i<k;i++){int j=0;for(j=0;j<len-1;j++){*(arr+j)=*(arr+j+1);}*(arr+len-1)=tm
2022-01-01 21:41:40
141
原创 趣味函数(真假话)
5名运动员参加了比赛a说:b第二,a第一;b说:b第二,e第四;c说:c第一,d第二;d说:c最后,d第三;e说:e第四,a第一;比赛结束后,每名选手都说对了一半,请编程确定比赛的名次#include<stdio.h>int main(){int a,b,c,d,e;for(a=1;a<=5;c++){for(b=1;b<=5;b++){for(c=1;c<=5;c++){for(d=1;d<=5;d++){rof(e=1;
2022-01-01 19:39:45
137
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人