![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数据结构
迪迪迪迪迪迪
大三本科在读,自学编程,本科专业是工商管理
展开
-
数据结构之创建线索二叉树并打印
//创建线索二叉树并遍历#include<stdio.h>#include<stdlib.h>//线索存储标志位//Link(0),表示指向左右孩子的指针//Thread(1),表示指向该结点的前驱后继typedef enum{Link,Thread}PointerNag;typedef char ElemType;//创造线索二叉树的结构typedef struct BiThrNode { char data; struct BiThrNode *lc.原创 2021-08-05 17:53:13 · 172 阅读 · 6 评论 -
数据结构之前序遍历二叉树并打印所在层数
//前序遍历二叉树并打印层数#include<stdio.h>#include<stdlib.h>//构造二叉树结构typedef struct BiTNode { char data; struct BitTree* lchild; struct BitTree* rchild;}BiTNode, * BiTree;//二叉树的初始化CreateBiTree(BiTree* T) { char c; scanf("%c", &c); if (.原创 2021-08-05 17:51:33 · 607 阅读 · 1 评论 -
数据结构之八皇后问题(递归算法)
//八皇后问题#include<stdio.h>int count=0;//全局变量countint notDanger(int row, int j, int(*chess)[8]) { int i,r,flat1=0,flat2=0,flat3=0,flat4=0,flat5=0; //判断纵列有没有其他皇后 for (i = 0; i < 8; i++) { if (*(*(chess + i) + j) != 0) { flat1 = 1; br.原创 2021-08-05 17:49:26 · 157 阅读 · 0 评论 -
数据结构之递归:斐波那契问题
//用递归解决斐波那契问题#include<stdio.h>int main(void) { int n ,i; int a[40] = { 0 }; scanf("%d", &n); i = fib(n); printf("%d",i);}int fib(n) { if (n < 2) return n == 0 ? 0 : 1; return fib(n - 1) + fib(n - 2);}小白的自学之路,欢迎大家前来交流和讨论!...原创 2021-08-05 17:43:46 · 60 阅读 · 0 评论 -
数据结构之汉诺塔问题
//汉诺塔问题#include<stdio.h>void move(int n,char x,char y,char z);int main(void) { int n; printf("请输入需要汉诺塔的层数:\n"); scanf("%d", &n); printf("步骤如下:\n"); move(n, 'X', 'Y', 'Z'); return 0;}void move(int n, char x, char y, char z) { if (n ==.原创 2021-08-05 17:42:12 · 153 阅读 · 0 评论 -
数据结构之KMP算法
//KMP算法#include<stdio.h>typedef char* String;void get_next(String T, int* next) { int i = 1; int j = 0; next[1] = 0; while (i <= T[0]) { if (j == 0 || T[i] == T[j]) { i++; j++; if (T[i] != T[j]) { next[i] = j; } else .原创 2021-08-05 17:40:31 · 59 阅读 · 0 评论 -
数据结构之二叉树的双亲孩子表示法
//双亲孩子表示法#define MAX_TREE_SIZE 100typedef char ElemType;typedef struct Child//孩子结点{ ElemType data;//数据 int child;//当前孩子的下标 struct Child *next;//指向下一个孩子结点 }*ChildPtr;//别名为指向该结构的指针typedef struct PTNode//表头结点{ int parent;//父母结点的下标 ElemType .原创 2021-08-05 17:38:43 · 883 阅读 · 0 评论 -
数据结构之逆波兰表达式的用法
//逆波兰表达式:将中缀表达式转换为后缀表达式#include<stdio.h>#include<stdlib.h>#include<math.h>#define STACK_INIT_SIZE 20#define STACKINCREAMENT 10typedef char ElemType;//栈结构typedef struct { ElemType* base; ElemType* top; int stackSize;}sqSta.原创 2021-08-05 17:37:10 · 112 阅读 · 0 评论 -
数据结构之链队列的链式存储使用
//链队列的链式存储使用#include<stdio.h>#include<stdlib.h>typedef char ElemType;typedef struct LNode { ElemType data; struct LNode* next;}LNode,*QueuePtr;//构造链结构typedef struct QueueList { QueuePtr front, rear;}QueueList;//;构造链队列的结构//创建队列.原创 2021-08-05 17:32:48 · 75 阅读 · 0 评论 -
数据结构之双向链表习题
双向链表较单链表更为复杂,但同时更加灵活,以下是运用双向链表对26个字母的自定义排序,用户输入【-26,26】区间的数字来调整字母的顺序,以下是源代码(本人新手,代码仅供自学和记录)://双向链表的实践#include<stdio.h>#include<stdlib.h>typedef struct node{ char data; struct node *prior; struct node *next;}node;node* create(char原创 2021-07-23 21:01:28 · 319 阅读 · 0 评论 -
循环链表之魔法师发牌问题
Magician问题也是循环链表的经典问题,尽管其逻辑比较通俗易懂,但是用代码将其实现的方式更灵活,也更有味道。以下是源代码(本人新手,仅供自学和记录)://魔术师发牌问题#include<stdio.h>#include<stdlib.h>typedef struct node{ char data; struct node* next;}node;node* create(int n) { //初始化链表; node* p = NULL, * he原创 2021-07-23 20:55:29 · 88 阅读 · 0 评论 -
循环链表之约瑟夫问题
Josephus问题是循环链表中的经典问题,该代码逻辑了循环链表的特性,实现的功能为:每次数数从1开始数,把数到为3的数将其删除,然后往下继续从1开始数,把下一个为数到3的数删掉,依次类推,直到全部删除。以下是源代码,本人新手,代码当做自我学习和记录(C语言)://约瑟夫问题#include<stdio.h>#include<stdlib.h>typedef struct node{ int data; struct node *next;}node;n原创 2021-07-23 20:49:43 · 155 阅读 · 0 评论