
数据结构
Ming_He2
To Iterate is Human, to Recurse, Divine.
展开
-
二叉树的前序和中序遍历 非递归实现
二叉树的前序和中序遍历 非递归实现 前序非递归遍历 记录下学习二叉树的过程,对二叉树遍历的递归写法不太理解,因此使用非递归写法,模拟递归过程,加深理解对递归过程理解。(学完发现,还是递归香) #include<bits/stdc++.h> using namespace std; //定义一棵树 typedef struct T{ int val; struct T *lNode; struct T *rNode; }T; //初始化根节点 T* initT(T *r原创 2022-04-03 17:36:28 · 1403 阅读 · 0 评论 -
双向链表(插入和删除)
在这里插入代码片#include <iostream> using namespace std; typedef int Elem; typedef struct Node{ Elem data; Elem index = -1; struct Node* pre; struct Node* next; }node; //初始化链表 node* initDoubleList() { node* head = (node*)malloc(sizeof(n原创 2021-06-07 09:34:35 · 255 阅读 · 0 评论 -
单链表的创建及对应操作(增删改查)
#include <iostream> using namespace std; typedef struct Node{ int data; struct Node* next; }node; //初始化链表 node* initList(){ node* head = (node*)malloc(sizeof(node)); node* temp = head;//临时节点记录头结点,不能直接使用头结点遍历,否则容易造成头结点地址丢失 for(in原创 2021-06-06 17:41:00 · 158 阅读 · 0 评论