![](https://img-blog.csdnimg.cn/20190918140158853.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
数据结构
数据结构相关代码
「已注销」
这个作者很懒,什么都没留下…
展开
-
数据结构——028树的存储结构(只含双亲表示法,待更)
//双亲表示法#include<iostream>using namespace std;#define MaxSize 50typedef struct { char d1; int d2;}PNode;typedef struct { PNode T[MaxSize]; int n;//结点的个数}PTree;PTree init_tree() { PTree t; int n; cout << "请输入结点个数:"; cin >> n原创 2020-05-10 19:30:53 · 128 阅读 · 0 评论 -
数据结构——027中序线索二叉树
//中序线索二叉树typedef struct ThreadNode { ElemType data; ThreadNode *lchild, *rchild; int ltag, rtag;}ThreadNode,*ThreadTree;void InThread(ThreadTree &t, ThreadTree &pre) { if (t) { InThread(t->lchild, pre); if (t->lchild == NULL) {原创 2020-05-10 19:29:18 · 157 阅读 · 0 评论 -
数据结构——026树的层次遍历
#include <iostream>using namespace std;#define MaxSize 50typedef int ElemType;typedef struct BT { ElemType data; struct BT* lchild; struct BT* rchild;}BT, *BiTree;typedef struct Queue{ BiTree data[MaxSize]; int front; int rear;}SqQueue;原创 2020-05-10 19:28:02 · 164 阅读 · 0 评论 -
数据结构——025中序遍历的非递归遍历
#include <iostream>using namespace std;#define MaxSize 50typedef int ElemType;typedef struct BT { ElemType data; struct BT* lchild; struct BT* rchild;}BT, *BiTree;typedef struct Stack { BiTree data[MaxSize]; int top;}SqStack;void init_s(原创 2020-05-10 19:25:58 · 271 阅读 · 0 评论 -
数据结构——024树的先中后递归遍历
#include <iostream>using namespace std;typedef int ElemType;typedef struct BT { ElemType data; struct BT* lchild; struct BT* rchild;}BT, *BiTree;//树的建立BiTree Create_T() { BiTree T = new BT; T->data = 1; T->lchild = new BT; T->lch原创 2020-05-10 19:25:02 · 77 阅读 · 0 评论 -
数据结构——022串的模式匹配算法(BF)
#include <iostream>#include <string>using namespace std;//普通模式匹配算法(BF)int Index(string s1,string s2) {//s1为主串,s2为模式串 int i = 0, j = 0; while (i < s1.size() && j < s2.size()) { if (s1[i] == s2[j]) { i++; j++; } e原创 2020-05-10 19:24:09 · 173 阅读 · 0 评论 -
数据结构——016中缀转后缀表达式
//中缀转后缀表达式//1.若为'(',直接入栈//2.若为')',出栈直到'(',并删掉栈中的'('//3.若为'+','-','*','/’// (1)栈空,入栈// (2)若栈顶为'(',入栈// (3)若比栈顶优先级高,入栈// 否则,弹出栈顶元素,直到出现'('或者比栈顶优先级低//4.遍历完成,若栈非空依次弹出所有元素#include <iostream>#include <string>using namespace std;#define M原创 2020-05-10 19:23:05 · 98 阅读 · 0 评论 -
数据结构——015括号匹配
//括号匹配#include <iostream>#include <string>using namespace std;#define MaxSize 50typedef char Elem;typedef struct Stack { Elem data[MaxSize]; int top;}SqStack;void init_s(SqStack &s) { s.top = -1;}bool empty_s(SqStack s) { if原创 2020-05-10 19:22:16 · 105 阅读 · 0 评论 -
数据结构——012循环队列
//长度int length_q(SqQueue q) { return (q.rear + MaxSize - q.front) % MaxSize;}//入队bool enqueue(SqQueue &q,ElemType e) { if ((q.rear+1)%MaxSize == q.front) return false; q.data[q.rear] = e; q.rear = (q.rear + 1) % MaxSize; return true;}//出队原创 2020-05-10 19:21:29 · 151 阅读 · 0 评论 -
数据结构——011队列
//队列//只允许在表的一端进行插入,另一端进行删除//队头进行删除操作,队尾进行插入操作//基本操作//初始化,判空,入队,出队,获取队头元素,销毁#include<iostream>using namespace std;#define MaxSize 50typedef int ElemType;//顺序队列typedef struct Queue { ElemType data[MaxSize]; int front; int rear;}SqQueue;原创 2020-05-10 19:20:44 · 108 阅读 · 0 评论 -
数据结构——009顺序栈
#include <iostream>using namespace std;#define MaxSize 50typedef int ElemType;//顺序存储结构typedef struct Stack { ElemType data[MaxSize]; int top;}SqStack;//初始化void InitStack(SqStack &s) { s.top = -1;}//判空bool empty_s(SqStack s) { if原创 2020-05-10 19:19:51 · 162 阅读 · 0 评论 -
数据结构——008单链表的合并
#include <iostream>using namespace std;typedef int ElemType;typedef struct LNode { ElemType data; struct LNode* next;}LNode,*LinkList;//初始化链表(含有头结点)LinkList init_linklist() { LinkList p = new LNode;//头结点 p->next = NULL; LinkList L = p;/原创 2020-05-09 11:10:16 · 136 阅读 · 0 评论 -
数据结构——007单链表的逆置
#include <iostream>using namespace std;typedef int ElemType;typedef struct LNode { ElemType data; struct LNode* next;}LNode,*LinkList;//初始化链表(含有头结点)LinkList init_linklist() { LinkList p = new LNode;//头结点 p->next = NULL; LinkList L = p;/原创 2020-05-09 11:09:36 · 161 阅读 · 0 评论 -
数据结构——003双向链表
//双链表#include <iostream>using namespace std;typedef int ElemType;typedef struct LNode { ElemType data; struct LNode* prior; struct LNode* next;}LNode, *LinkList;//初始化LinkList init_linklist() { LinkList p = new LNode;//头结点 p->next = NU原创 2020-05-09 11:08:15 · 216 阅读 · 0 评论 -
数据结构——002单链表
#include <iostream>using namespace std;//线性表的链式表示//通过指针实现线性逻辑关系//结点:数据域,指针域//单链表的基本操作//头插法建立typedef int ElemType;typedef struct LNode { ElemType data; struct LNode* next;}LNode,*LinkList;//初始化链表(含有头结点)LinkList init_linklist() { LinkL原创 2020-05-09 11:07:26 · 92 阅读 · 0 评论 -
数据结构——001线性表的顺序表示
//线性表的顺序表示#include <iostream>using namespace std;//顺序表//**顺序表是从1开始的,数组是从0开始的typedef int ElemType;//数组静态分配#define Size 5typedef struct{ int length; ElemType data[Size];}SqList;//数组动态分配typedef struct { ElemType *data; int length; int s原创 2020-05-09 11:00:28 · 158 阅读 · 0 评论