随笔分类 - 数据结构与算法
摘要:数组的时间复杂度 操作 时间复杂度 头插(vector没有此操作) O(1) push_back O(1) insert O(n) erase O(n) 随机访问 O(1) 链表的时间复杂度 操作 时间复杂度 push_front(头插) O(1) push_back O(1) insert O(1
阅读全文
摘要:在面试的时候我们经常被问到堆和栈相关的问题,悲催的是还傻傻分不清面试官要问的是哪个堆栈。 是的,堆和栈有两层含义,分别对应如下两个方面: 数据结构中的堆和栈、以及队列 1. 堆 官方定义如下:n个元素的序列{k1, k2, … kn},当且仅当满足以下关系时称之为堆: 堆其实就是利用完全二叉树的结构
阅读全文
摘要:3 #include 4 #include 5 void Swap(int &a, int &b) 6 { 7 int t = a; 8 a = b; 9 b = t; 10 } 11 12 13 //选择排序:交换移动次数少,O(n2) 14 void SelectSort(int a[],int n)//或者int *a...
阅读全文
摘要:1 1//代码来自浙大数据结构的讲义 2 #include 3 #include 4 5 typedef struct Node 6 { 7 ElementType Data; 8 struct Node *Next; 9 }List; 10 List L, *ptrL; 11 12 //////////////////////...
阅读全文
摘要:1 //代码来自浙大数据结构的讲义 2 #include 3 #include 4 #define MAXSIZE 10 5 6 typedef struct { 7 ElementType Data[MAXSIZE]; 8 int last; //这里的last代表,顺序表最后一个元素的下标,若有n个元素,其值为n-1. MAXSIZE代表表的最大容...
阅读全文