当前位置: 首页 > news >正文

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 };

 

转载于:https://www.cnblogs.com/hzoi-lsc/p/11463534.html

相关文章:

  • 顶层const 底层const
  • 期末考试(正解:三分单峰函数 me~)
  • const 成员函数
  • Linux——CentOS7没有第二张网卡的配置信息
  • Python3.5学习之旅——day5
  • zabbix监控jvm内存
  • 约瑟夫环算法的几种实现方式,最简单方式,一行代码实现
  • NPM——npm|cnpm如何升级
  • Nginx——报错汇总
  • 贪心算法基础
  • ElementUI——报错汇总
  • ElementUI——动态表单验证
  • CSP-S 46 题解
  • maven引入本地jar包的方法
  • jmap错误:unknown CollectedHeap type : class sun.jvm.hotspot.gc_interface.CollectedHeap
  • (三)从jvm层面了解线程的启动和停止
  • angular学习第一篇-----环境搭建
  • js面向对象
  • Linux后台研发超实用命令总结
  • Nodejs和JavaWeb协助开发
  • python 学习笔记 - Queue Pipes,进程间通讯
  • python大佬养成计划----difflib模块
  • 闭包,sync使用细节
  • 闭包--闭包作用之保存(一)
  • -- 查询加强-- 使用如何where子句进行筛选,% _ like的使用
  • 记录一下第一次使用npm
  • 开发了一款写作软件(OSX,Windows),附带Electron开发指南
  • 聊聊sentinel的DegradeSlot
  • 聊聊springcloud的EurekaClientAutoConfiguration
  • 排序算法之--选择排序
  • 融云开发漫谈:你是否了解Go语言并发编程的第一要义?
  • 小程序button引导用户授权
  • 一起来学SpringBoot | 第十篇:使用Spring Cache集成Redis
  • 译米田引理
  • 用Canvas画一棵二叉树
  • Semaphore
  • shell使用lftp连接ftp和sftp,并可以指定私钥
  • ​软考-高级-信息系统项目管理师教程 第四版【第19章-配置与变更管理-思维导图】​
  • ​香农与信息论三大定律
  • ###C语言程序设计-----C语言学习(6)#
  • ()、[]、{}、(())、[[]]等各种括号的使用
  • (10)Linux冯诺依曼结构操作系统的再次理解
  • (C语言)strcpy与strcpy详解,与模拟实现
  • (JS基础)String 类型
  • (python)数据结构---字典
  • (附源码)spring boot基于小程序酒店疫情系统 毕业设计 091931
  • (附源码)ssm高校实验室 毕业设计 800008
  • (转)setTimeout 和 setInterval 的区别
  • (转)关于多人操作数据的处理策略
  • (转载)微软数据挖掘算法:Microsoft 时序算法(5)
  • (轉貼) UML中文FAQ (OO) (UML)
  • .Net MVC + EF搭建学生管理系统
  • .NET平台开源项目速览(15)文档数据库RavenDB-介绍与初体验
  • [ Linux Audio 篇 ] 音频开发入门基础知识
  • [【JSON2WEB】 13 基于REST2SQL 和 Amis 的 SQL 查询分析器