zoukankan      html  css  js  c++  java
  • STL.h

    最近老是被系统的一些STL卡到飞起,然后就手打了一个STL.h 库函数还没有打完,以后打新的还会再更,大家也可以使用,顺便帮我找一下bug,然后我再改进!

     1 template< typename RT >class queue
     2 {
     3     public:
     4     RT sta[10000005];
     5     int l,r;
     6     void clear(){l=r=0;}
     7     inline void push(RT x){sta[r++]=x;return ;}
     8     inline void pop(){l++;return ;}
     9     inline RT front(){return sta[l];}
    10     inline bool empty(){return r==l;}
    11     inline bool size(){return r!=l;}
    12 };
    13 template< typename RT >class stack
    14 {
    15     public:
    16     RT sta[10000005];
    17     int topp;
    18     void clear(){topp=0;}
    19     inline void push(RT x){sta[++topp]=x;return ;}
    20     inline void pop(){topp--;return ;}
    21     inline bool empty(){return topp==0;}
    22     inline bool size(){return topp;}
    23     inline bool top(){return sta[topp];}
    24 };
    25 template< typename RT >class hash_table
    26 {
    27     public:
    28     int mod;
    29     inline void init(int x){mod=x;return ;}
    30     int head[100005],vvt[100005],nxt[100005],tot;
    31     RT ver[100005];
    32     inline void insert(int x,RT ac)
    33     {
    34         int u=x%mod;
    35         for(int i=head[u];i;i=nxt[i])
    36         {
    37             RT y=ver[i];
    38             if(y==ac){vvt[i]++;return ;}
    39         }
    40         ver[++tot]=ac;
    41         nxt[tot]=head[u];
    42         head[u]=tot;
    43         vvt[tot]++;
    44     }
    45     inline int query_times(int x,RT ac)
    46     {
    47         int u=x%mod;
    48         for(int i=head[u];i;i=nxt[i])
    49         {
    50             RT y=ver[i];
    51             if(y==ac)return vvt[i];
    52         }
    53         return 0;
    54     }
    55 };

    //////未完/////////

    2019.9.23 UPDATE

    更新了queue和stack的大小参数和一些骚操作!

    hash_table 没有更新!

     1 //#include<iostream>
     2 //#include<cstdio>
     3 //#include<cstdlib>
     4 //#include<algorithm>
     5 //using namespace std;
     6 
     7 
     8 //make by lsc; %%%stl
     9 template<typename RT,int MAXN>
    10 class stack
    11 {
    12     public:
    13     RT sta[MAXN];int topp;
    14     inline void clear(){topp=0;return ;}
    15     inline void init(){topp=0;return ;}
    16     inline void push(RT x){sta[++topp]=x;return ;}
    17     inline int size(){return topp;}
    18     inline bool empty(){return topp;}
    19     inline int bottom(){if(topp==0)return -(1<<10);else return sta[1];}
    20     inline int num(RT x){return sta[x];}
    21     inline void sort_stack(RT x){sort(sta+1,sta+topp+1);if(x)return ;else reverse(sta+1,sta+topp+1);return ;}//如果x==1,从小到大,else less; 
    22     /*
    23      if struct sort please make function!
    24      */
    25 };
    26 template<typename RT,int MAXN>
    27 class queue
    28 {
    29     public:
    30     #define re register
    31     RT sta[MAXN];
    32     int fr,back;
    33     inline void init(){fr=1;back=0;}
    34     inline void push(re RT x){sta[++back]=x;return ;}
    35     inline void pop(){fr++;return ;}
    36     inline RT front(){return sta[fr];}
    37     inline bool empty(){if(back>=fr)return 0;else return 1;}
    38     inline bool size(){if(back<=fr)return 0;else return 1;}
    39     inline void sort_queue(RT x){sort(sta+back,sta+fr+1);if(x)return ;else reverse(sta+back,sta+fr+1);return ;}
    40 };

     UPDATE 新版本!

     1 /*
     2 #include<iostream>
     3 #include<cstdio>
     4 #include<cstdlib>
     5 #include<algorithm>
     6 using namespace std;
     7 */
     8 
     9 //make by lsc; %%%stl
    10 template<typename RT,int MAXN>
    11 class stack
    12 {
    13     public:
    14     RT sta[MAXN];int topp;
    15     inline void clear(){topp=0;return ;}
    16     inline void init(){topp=0;return ;}
    17     inline void push(RT x){sta[++topp]=x;return ;}
    18     inline int size(){return topp;}
    19     inline bool empty(){return topp;}
    20     inline int bottom(){if(topp==0)return -(1<<10);else return sta[1];}
    21     inline int num(RT x){return sta[x];}
    22     inline void pop(){topp--;if(topp<0)topp=0;return ;}
    23     inline void sort_stack(RT x){sort(sta+1,sta+topp+1);if(x)return ;else reverse(sta+1,sta+topp+1);return ;}//如果x==1,从小到大,else less; 
    24     /*
    25      if struct sort please make function!
    26      */
    27 };
    28 template<typename RT,int MAXN>
    29 class queue
    30 {
    31     public:
    32     #define re register
    33     RT sta[MAXN];
    34     int fr,back;
    35     inline void init(){fr=1;back=0;}
    36     inline void push(re RT x){sta[++back]=x;return ;}
    37     inline void pop(){fr++;return ;}
    38     inline RT front(){return sta[fr];}
    39     inline bool empty(){if(back>=fr)return 0;else return 1;}
    40     inline bool size(){if(back<=fr)return 0;else return 1;}
    41     inline void sort_queue(RT x){sort(sta+back,sta+fr+1);if(x)return ;else reverse(sta+back,sta+fr+1);return ;}
    42 };
    43 
    44 template<typename RT,int MAXN>
    45 class priority_queue
    46 {
    47     public:
    48     RT q[MAXN];int sz;
    49     priority_queue(){sz=0;}
    50     inline void push(int x)
    51     {
    52         q[++sz]=x;
    53         for(int i=sz,j=i>>1;j;i=j,j>>=1)
    54             if(q[j]>q[i])swap(q[j],q[i]);
    55     }
    56     inline void pop()
    57     {
    58         q[1]=q[sz--];
    59         for(int i=1,j=i<<1;j<=sz;i=j,j<<=1)
    60         {
    61             if((j|1)<=sz&&q[j|1]<q[j])j=j|1;
    62             if(q[i]>q[j])swap(q[i],q[j]);
    63             else break;
    64         }
    65     }
    66     inline RT top(){return q[1];}
    67 };
    68 //UPDATE 2019.9.23 pair 未经过测试!
    69 template<typename RT,typename RE>
    70 class pair
    71 {
    72     public:
    73     RT first;RE second;
    74     pair(){first=0,second=0;}
    75     inline void make_pair(RT a,RE b){first=a,second=b;return ;}
    76     /*
    77      THIS FUNCTION THE DIRECTOR DIDN'T TRUST IT ,SO THE THINGS AFTER YOU USE IT ONLY YOU BEAR!    
    78      */
    79 };

     UPDATE 2019.9.26 整理了一下,但没有测试!

      1 /*
      2 #include<iostream>
      3 #include<cstdio>
      4 #include<cstdlib>
      5 #include<algorithm>
      6 using namespace std;
      7 */
      8 
      9 //make by lsc; %%%stl
     10 template<typename RT,int MAXN>
     11 class stack
     12 {
     13     public:
     14     RT sta[MAXN];int topp;
     15     inline void clear(){topp=0;return ;}
     16     inline void init(){topp=0;return ;}
     17     inline void push(RT x){sta[++topp]=x;return ;}
     18     inline int size(){return topp;}
     19     inline bool empty(){return topp;}
     20     inline int bottom(){if(topp==0)return -(1<<10);else return sta[1];}
     21     inline int num(RT x){return sta[x];}
     22     inline void pop(){topp--;if(topp<0)topp=0;return ;}
     23     inline void sort_stack(RT x){sort(sta+1,sta+topp+1);if(x)return ;else reverse(sta+1,sta+topp+1);return ;}//如果x==1,从小到大,else less; 
     24     /*
     25      if struct sort please make function!
     26      */
     27 };
     28 template<typename RT,int MAXN>
     29 class queue
     30 {
     31     public:
     32     #define re register
     33     RT sta[MAXN];
     34     int fr,back;
     35     inline void init(){fr=1;back=0;}
     36     inline void push(re RT x){sta[++back]=x;return ;}
     37     inline void pop(){fr++;return ;}
     38     inline RT front(){return sta[fr];}
     39     inline bool empty(){if(back>=fr)return 0;else return 1;}
     40     inline bool size(){if(back<=fr)return 0;else return 1;}
     41     inline void sort_queue(RT x){sort(sta+back,sta+fr+1);if(x)return ;else reverse(sta+back,sta+fr+1);return ;}
     42 };
     43 
     44 template<typename RT,int MAXN>
     45 class priority_queue
     46 {
     47     public:
     48     RT q[MAXN];int sz;
     49     priority_queue(){sz=0;}
     50     inline void push(int x)
     51     {
     52         q[++sz]=x;
     53         for(int i=sz,j=i>>1;j;i=j,j>>=1)
     54             if(q[j]>q[i])swap(q[j],q[i]);
     55     }
     56     inline void pop()
     57     {
     58         q[1]=q[sz--];
     59         for(int i=1,j=i<<1;j<=sz;i=j,j<<=1)
     60         {
     61             if((j|1)<=sz&&q[j|1]<q[j])j=j|1;
     62             if(q[i]>q[j])swap(q[i],q[j]);
     63             else break;
     64         }
     65     }
     66     inline RT top(){return q[1];}
     67 };
     68 
     69 //UPDATE 2019.9.23 pair 未经过测试!
     70 template<typename RT,typename RE>
     71 class pair
     72 {
     73     public:
     74     RT first;RE second;
     75     pair(){first=0,second=0;}
     76     inline void make_pair(RT a,RE b){first=a,second=b;return ;}
     77     /*
     78      THIS FUNCTION THE DIRECTOR DIDN'T TRUST IT ,SO THE THINGS AFTER YOU USE IT ONLY YOU BEAR!    
     79      */
     80 };
     81 
     82 template< typename RT >class hash_table
     83 {
     84     public:
     85     int mod;
     86     inline void init(int x){mod=x;return ;}
     87     int head[100005],vvt[100005],nxt[100005],tot;
     88     RT ver[100005];
     89     inline void insert(int x,RT ac)
     90     {
     91         int u=x%mod;
     92         for(int i=head[u];i;i=nxt[i])
     93         {
     94             RT y=ver[i];
     95             if(y==ac){vvt[i]++;return ;}
     96         }
     97         ver[++tot]=ac;
     98         nxt[tot]=head[u];
     99         head[u]=tot;
    100         vvt[tot]++;
    101     }
    102     inline int query_times(int x,RT ac)
    103     {
    104         int u=x%mod;
    105         for(int i=head[u];i;i=nxt[i])
    106         {
    107             RT y=ver[i];
    108             if(y==ac)return vvt[i];
    109         }
    110         return 0;
    111     }
    112 };
    113 //2019.9.26 UPDATE
    114 //lower_bound but didn't test ,you can test it ,but not int exam!
    115 //I dont't konw if it has bugs!
    116 template<typename RT,typename RE>
    117 RE lower_bound(RT *a,RE l,RE r)
    118 {
    119     while(l<r)
    120     {
    121         int mid=(l+r)>>1;
    122         if(a[mid]>=r)r=mid;
    123         else l=mid+1;
    124     }
    125     return l;
    126 };
  • 相关阅读:
    一个apache安装后无法启动的原因分析
    数字的一点考虑
    [转]bat方式上删除注册表键,项
    题解 P2016 【战略游戏】
    题解 P1403 【[AHOI2005]约数研究】
    题解 P1317 【低洼地】
    2020面向对象程序设计寒假作业3 设计思想
    题解 P1829 【[国家集训队]Crash的数字表格 / JZPTAB】
    题解 P1082 【同余方程】
    Unity3D读取外部Text
  • 原文地址:https://www.cnblogs.com/hzoi-lsc/p/11463534.html
Copyright © 2011-2022 走看看