码迷,mamicode.com
首页 > 其他好文 > 详细

数据结构

时间:2017-11-07 12:12:23      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:stl   删除   opened   insert   return   amp   closed   void   过程   

数据结构这种东西敲起来十分爽

数据结构往往替代了我们思考的过程,但还是比较好用的

虽然STL已经内置了很多数据结构,但是NOIP不开O2。。。。。

所以很慢很慢很慢。。。。。nlogn会变成n^2,。。。。所以还是自己写吧

从最基本的开始

队列(队列是一种先进先出的数据结构)

技术分享
//加入操作
inline void push_up(int x){
    q[++tail]=x;
} 
//取队列最前端的元素
inline int top(){
    return q[head];
} 
//删除队列最前面的元素并返回元素 
inline void pop(){
     return q[head++];
} 
//判断队列是否为空
inline bool empty(){
    if(head<=tail) return true;
    else true false;
} 
View Code

栈(栈与队列不同,废话名字都不一样,栈是维护先进后出的一种数据结构)

技术分享
//加入操作
inline void push_up(int x){
    q[++top]=x;
} 
//取栈最顶端的元素
inline int top(){
    return q[top];
} 
//删除栈最前面的元素并返回元素 
inline void pop(){
     return q[--top];
} 
View Code

有关树的结构

树状数组(树状数组是维护动态区间和的一个极有利的数据结构)

技术分享
inline lowbit(int x){
    return x&-x;
}
inline void insert(int x){
    while(x<MAXN){
        c[x]+=v;
        x+=lowbit(x); 
    }
}
inline long long search(int x){
    long long sum;
    while(x){
        sum+=c[x];
        x-=lowbit(x);
    }
    return sum;
}
View Code

 

数据结构

标签:stl   删除   opened   insert   return   amp   closed   void   过程   

原文地址:http://www.cnblogs.com/something-for-nothing/p/7798293.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!