随笔分类 - 数据结构
摘要:https://www.cs.usfca.edu/~galles/visualization/Algorithms.html 基本概念 A directed graph is called strongly connected if there is a directed path from any
阅读全文
摘要:树 基本概念 1.最多一个先驱 但可能有多个后继 表示具有层次的分支关系 2.Siblings(兄弟): nodes share the same parent Degree(树的扇出) of a tree: the maximum number of its node. 3.深度为最大层数 第i层
阅读全文
摘要:1.栈 栈顶在数组尾 栈底在数组头 2.队列 循环队列 count=maxqueue; front=0; rear=maxqueue-1; 利用循环队列 可以很好的利用先前出队元素所剩下的空间 3.堆 extract-max O(logn) T(n)=2(T(n/2))+O(n) O(1)=1 in
阅读全文
摘要:类内操作符重载#include<iostream> using namespace std; class complex { //复数类 public: //外部接口 complex(double r = 0.0, double i = 0.0) { real = r; imag = i; } //
阅读全文
摘要:数据结构期末复习(C++部分) 1.参数传递 1)值传递 形参是实参的拷贝,改变形参的值不会影响实参的值 传递是单向的 从实参到形参 参数的值只能传入,不能传出 pass in the copy 2)引用传递 pass in the variable itself doesn't have to m
阅读全文
摘要:链表中的头指针和头结点 链式存储 指针域(单链表),来记录下一个结点的存储位置(地址) 插入和删除结点时,只需要修改指针即可 struct node{ int data; struct node *next; } data是数据域,用于存储数据 next是指针域,用于存储下一个结点的位置(地址)
阅读全文
摘要:树的遍历及复杂度分析 时间复杂度:由于要遍历树的所有节点,故时间复杂度均为O(n) 空间复杂度:递归算法用函数栈实现,空间复杂度即为栈的深度,也即树的高度O(logn) 此时的栈中存参数,函数指针,局部变量。 前序遍历 print(TreeNode * root) { if(root!=NULL){
阅读全文
摘要:tests.h #include<iostream> using namespace std; struct ListNode{ ListNode(){}; int data; ListNode *next;
阅读全文
摘要:栈的应用 1.数制转换 十进制数N转化为r进制数 N N/r N%r 思路 N对r取模直到N/R=0 将余数从下往上写 2.栈的应用--解迷宫问题 按南东北西的优先级走 沿着某个方向走到走不下去再沿着另一个方向走 每个格子有四种可能的状态 0 1 i @ 除0外都不能走 i 表示已经在栈内的路 @
阅读全文
摘要:数据结构 队列 1.概念 从队尾入队 从队首出队 FIFO First in first out 2.课堂练习 用两个队列实现栈 图(1):当栈里面插入元素“abcd”的时候,元素a在栈底(最后出去),d在栈顶(最先出去); 图(2):将元素“abc”从q1中头删,然后再q2中尾插进来之后,头删q1
阅读全文
摘要:讲解链接https://blog.51cto.com/9291927/2063393 https://blog.csdn.net/hguisu/article/details/7674195 1.栈的概念 store a set of elements in a particular order L
阅读全文
摘要:算法导论 第三章 函数的增长 1.渐近紧确界 渐近记号Θ、Ο、o、Ω、ω详解 链接:https://blog.csdn.net/so_geili/article/details/53353593##目录: 1.渐近紧确界记号:Θ ΘΘ(big-theta)2.渐近上界记号 :O OO(big-oh)
阅读全文
摘要:算法导论 第二章 算法基础 1.示例 INSERTION-SORT(A) for j=2 to A.length key=A[j]//要插入的元素A[j] //insertion A[j] into sequence A[1,2,...,j-1]. i=j-1//从第j-1个元素开始逐一比对 for
阅读全文
摘要:冒泡排序#include <iostream>using namespace std;void bubblesort1A(int A[],int n);int main() { int A[10]={0},n=0,i=0; cin>>n; for( i=0;i<n;i++) cin>>A[i]; b
阅读全文
摘要:int main(){ Line line(10.0); cout<<" "<<line.getLength()<<endl; line.setLength(6.0); cout<<" "<<line.getLength()<<endl; return 0;};注意主函数中需先声明line,类型为L
阅读全文
摘要:1.引用传递 #include<iostream>using namespace std;int cubeByRef( int& );int main(){ int number=5; int result; cout<<"number="<<number<<endl; result=cubeByR
阅读全文

浙公网安备 33010602011771号