![](https://img-blog.csdnimg.cn/20201014180756923.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数据结构
坚持不懈的ape
思考着 努力着 坚持着
展开
-
基于“C语言中动态分配内存空间”的浅思:
基于“C语言中动态分配内存空间”的浅思:实现“动态分配空间”无非是“malloc”,“realloc”,但说其动态,并不是真正意义的“动态”(在原有基础上操作,如链表)因为使用malloc是因为原来定义的空间不够用了,而用其扩充储存,malloc是重新开辟一部分比原来大的空间,并且将原来空间中内容(橙色部分)复制到新开辟的空间(黄色部分)中,并且用free函数来释放原来的空间(橙色部分)。如图:...原创 2022-02-19 13:38:41 · 504 阅读 · 0 评论 -
二叉树的基本操作(小系统)包含测试数据及错误思想
验证数据:ab##cd###具体代码如下#include <stdio.h>#include<stdlib.h>typedef struct node{ char data; struct node *rchild,*lchild;}BiTNode,*BiTtree;int count=0;int leafcount=0;int depth=0;void CreateTree(BiTNode **root){ char data原创 2021-05-22 15:14:28 · 447 阅读 · 0 评论 -
二叉树的基本操作(一)
二叉树的基本操作1:创建2:前序,中序,后序遍历3:统计结点数4:统计叶子结点数5:打印叶子结点6:计算二叉树的深度7:按树状打印二叉树8:复制二叉树下面是具体代码和解析#include <stdio.h>#include<stdlib.h>typedef char Elemtype;int countall=0; //存储结点数int leafcount=0; //存储叶子结点数int depth=0; //存储二叉树深度typedef st原创 2021-05-22 14:45:26 · 111 阅读 · 0 评论 -
栈的基本操作(小系统)(base,top)
栈的基本操作包含九个基本操作如下:#include <stdio.h>#include<string.h>#include<stdlib.h>#include<sys/malloc.h>#define OK 1#define ERROR 0#define STACK_INIT_SIZE 100#define STACKINCREMENT 10typedef int ElemType;typedef int Statu原创 2021-05-12 13:43:23 · 1597 阅读 · 0 评论 -
《串》(包含BF和KMP算法)
数据结构第四章《串》今天数据结构老师布置的一个小系统目的是实现串的比较、串的提取子串、串的简单模式匹配Brute-Force(布鲁特-福斯)算法、Knuth-Morris-Pratt(KMP)算法#include <stdio.h>#include<string.h>#define MAXSIZE 100typedef struct{ char data[MAXSIZE]; int length;}SqString;int strCompare(原创 2021-05-06 17:06:42 · 196 阅读 · 0 评论 -
单链表查找倒数第k个数字
这是耿国华版《数据结构》第二章第十题(1)描述算法的基本设计思想这个其实很简单,无非是先创建好链表,把链表逆置(逆置时候需要注意先拆后合),逆置之后就是简单的单链表中基本操作中的按序号查找了(2)详细步骤就不说了,直接上代码吧具体详细的注释可以看我上一篇单链表逆置(方法二)#include <stdio.h>#include<stdlib.h>typedef struct Node{ int data; struct Node *next;}Nod原创 2021-04-24 15:20:43 · 291 阅读 · 0 评论 -
单链表存储实现逆置(方法二)
思路:1.先创建好链表2.进行逆置3.打印(注意问题和所犯错误已在代码上注释)#include <stdio.h>#include<stdlib.h>typedef struct Node{ int data; struct Node *next;}Node,*Linklist;Linklist InitList( int *a,int n){ Linklist head,p,q; int i; head=(Linklist原创 2021-04-24 11:16:00 · 227 阅读 · 0 评论 -
单链表存储实现逆置算法(图解)
#include <stdio.h>#include<stdlib.h>//结点类型定义typedef struct Node{int a;struct Node *next;}Node,*Linklist;Linklist listInit(int *data,int n){Linklist head,p,q;int i;head=(Node *)malloc(sizeof(Node));p=head;for(i=0;i<n;i++){q=(Node原创 2021-04-23 19:17:52 · 416 阅读 · 0 评论 -
单链表存储实现逆置算法
#include <stdio.h>#include<stdlib.h>//结点类型定义typedef struct Node{ int a; struct Node *next;}Node,*Linklist;Linklist listInit(int *data,int n){ Linklist head,p,q; int i; head=(Node *)malloc(sizeof(Node)); p=head;原创 2021-04-22 17:28:12 · 411 阅读 · 0 评论 -
线性表的逆置(使用一维数组存储)
#include <stdio.h>#include<stdlib.h>#define OK 1#define ERROR -1#define MAX_SIZE 100typedef int Status;typedef int ElemType;typedef struct sqlist{ ElemType Elem[MAX_SIZE]; int last; //last代表最后一个数数组下标}Sqlist;//打印函数void P原创 2021-04-22 14:04:27 · 732 阅读 · 1 评论 -
顺序栈的基本操作(静态分布空间)
顺序栈的基本操作(静态分布空间)//静态分配空间实现栈的基本操作#include <stdio.h>#include <stdlib.h>#define Stack_Size 50#define FALSE 0#define TRUE 1typedef int StackElementType;//顺序栈的存储结构可以用一位数组来表示typedef struct{ StackElementType elem[Stack_Size]; int top;原创 2021-04-14 17:50:47 · 396 阅读 · 0 评论 -
顺序栈基本操作(动态分配空间)
#include<stdio.h>#include<sys/malloc.h>#include<stdlib.h>#define ERROR 0#define OK 1#define STACK_INT_SIZE 5 /*存储空间初始分配量*/#define STACKINCREMENT 5 /*存储空间分配增量*/typedef int ElemType; /*定义元素类型*/typedef struct{ ElemType *base;原创 2021-04-22 12:47:12 · 763 阅读 · 1 评论