随笔分类 -  数据结构

二叉树根据层次遍历建树
摘要:前提是将二叉树扩充为完全二叉树 typedef struct bitree *Bnode; struct bitree{ int data; Bnode left,right; }; Bnode CreateTree(){ Bnode q[105]; int f=1,r=0; int num; Bn 阅读全文
posted @ 2020-07-10 21:32 qmzhna 阅读(518) 评论(0) 推荐(0)
Pop Sequence
摘要:Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, ..., N and pop randomly. You are supposed to tell if a given s 阅读全文
posted @ 2020-05-21 21:53 qmzhna 阅读(113) 评论(0) 推荐(0)
【数据结构】树状数组
摘要:引入 对于一个数列S=a1+a2+...+ak+...+an,我们有以下操作 1.区间求和:如要算[3,n-1]区间的和,则可以用前缀和Sn-1 - S3 2.对于ak,我们要加上d,则可以直接对ak进行操作 对于单步操作,如区间求和,它的时间复杂度为O(n),更新某个值为O(1)。但这仅仅是对于单 阅读全文
posted @ 2019-11-07 19:42 qmzhna 阅读(175) 评论(0) 推荐(0)
带头结点的单链表的创建
摘要:#include #include typedef struct Node { int data; struct Node *next; }Node; Node* CreatList(int n) { Node *head,*p,*q; head=(Node*)malloc(sizeof(Node)); q=head; for(int i=0;... 阅读全文
posted @ 2019-02-01 22:37 qmzhna 阅读(649) 评论(0) 推荐(0)