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

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

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=;return ;}
  16. inline void init(){topp=;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==)return -(<<);else return sta[];}
  21. inline int num(RT x){return sta[x];}
  22. inline void pop(){topp--;if(topp<)topp=;return ;}
  23. inline void sort_stack(RT x){sort(sta+,sta+topp+);if(x)return ;else reverse(sta+,sta+topp+);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=;back=;}
  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 ;else return ;}
  40. inline bool size(){if(back<=fr)return ;else return ;}
  41. inline void sort_queue(RT x){sort(sta+back,sta+fr+);if(x)return ;else reverse(sta+back,sta+fr+);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=;}
  50. inline void push(int x)
  51. {
  52. q[++sz]=x;
  53. for(int i=sz,j=i>>;j;i=j,j>>=)
  54. if(q[j]>q[i])swap(q[j],q[i]);
  55. }
  56. inline void pop()
  57. {
  58. q[]=q[sz--];
  59. for(int i=,j=i<<;j<=sz;i=j,j<<=)
  60. {
  61. if((j|)<=sz&&q[j|]<q[j])j=j|;
  62. if(q[i]>q[j])swap(q[i],q[j]);
  63. else break;
  64. }
  65. }
  66. inline RT top(){return q[];}
  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=,second=;}
  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=;return ;}
  16. inline void init(){topp=;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==)return -(<<);else return sta[];}
  21. inline int num(RT x){return sta[x];}
  22. inline void pop(){topp--;if(topp<)topp=;return ;}
  23. inline void sort_stack(RT x){sort(sta+,sta+topp+);if(x)return ;else reverse(sta+,sta+topp+);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=;back=;}
  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 ;else return ;}
  40. inline bool size(){if(back<=fr)return ;else return ;}
  41. inline void sort_queue(RT x){sort(sta+back,sta+fr+);if(x)return ;else reverse(sta+back,sta+fr+);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=;}
  50. inline void push(int x)
  51. {
  52. q[++sz]=x;
  53. for(int i=sz,j=i>>;j;i=j,j>>=)
  54. if(q[j]>q[i])swap(q[j],q[i]);
  55. }
  56. inline void pop()
  57. {
  58. q[]=q[sz--];
  59. for(int i=,j=i<<;j<=sz;i=j,j<<=)
  60. {
  61. if((j|)<=sz&&q[j|]<q[j])j=j|;
  62. if(q[i]>q[j])swap(q[i],q[j]);
  63. else break;
  64. }
  65. }
  66. inline RT top(){return q[];}
  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=,second=;}
  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[],vvt[],nxt[],tot;
  88. RT ver[];
  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 ;
  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)>>;
  122. if(a[mid]>=r)r=mid;
  123. else l=mid+;
  124. }
  125. return l;
  126. };

STL.h的更多相关文章

  1. 在查找预编译头时遇到意外的文件结尾。是否忘记了向源中添加“#include "StdAfx.h"”?

    在查找预编译头时遇到意外的文件结尾.是否忘记了向源中添加“#include "StdAfx.h"”? 右键选择该文件.cpp格式的->属性->预编译头,→ 不使用预编译 ...

  2. STLtoSVG,and SVG to Bmp

    先用这两个工具: Slic3R或者Skeinforge:这个两个工具的作用就是把STL文件切片为叠加的矢量图(SVG格式) 因为SVG是分层的,一层一层的把每层都转换成一张Bmp文件 听说ImageM ...

  3. C++客户端访问WebService VS2008

    VS2008及之后的版本已经不支持使用C++开发WEBService服务了,如果要在VS上开发WEBService,需要使用C#开发语言. 一.gSOAP简介 gSOAP编译工具提供了一个基于SOAP ...

  4. ubuntu 16.04 上使用pybind11进行C++和Python代码相互调用 | Interfacing C++ and Python with pybind11 on ubuntu 16.04

    本文首发于个人博客https://kezunlin.me/post/a41adc1/,欢迎阅读! Interfacing C++ and Python with pybind11 on ubuntu ...

  5. windows 10 上使用pybind11进行C++和Python代码相互调用 | Interfacing C++ and Python with pybind11 on windows 10

    本文首发于个人博客https://kezunlin.me/post/8b9c051d/,欢迎阅读! Interfacing C++ and Python with pybind11 on window ...

  6. VS2015 dlib编译 x64 Release .lib生成

    VS2015 dlib编译 x64 Release >------ 已启动生成: 项目: ZERO_CHECK, 配置: Release x64 ------ > Checking Bui ...

  7. VS2015 dlib编译 x64 Debug .lib生成

    VS2015 dlib编译 x64 Debug >------ 已启动生成: 项目: ZERO_CHECK, 配置: Debug x64 ------ > Checking Build S ...

  8. JMeter接口测试印象篇(win10)

    参考博文1:https://www.cnblogs.com/suim1218/p/9257369.html 参考博文2:https://blog.csdn.net/u011541946/article ...

  9. 混合编程:如何用python11调用C++

    摘要:在实际开发过程中,免不了涉及到混合编程,比如,对于python这种脚本语言,性能还是有限的,在一些对性能要求高的情景下面,还是需要使用c/c++来完成. 那怎样做呢?我们能使用pybind11作 ...

随机推荐

  1. mac下ip地址重定向

    在终端临时使用最高权限用vim编辑/etc下的hosts文件,若提示Password: 输入开机登录密码并回车: yanguobindeMacBook-Pro:~ yanguobin$ sudo vi ...

  2. 算法学习之剑指offer(十二)

    一 题目描述 请设计一个函数,用来判断在一个矩阵中是否存在一条包含某字符串所有字符的路径.路径可以从矩阵中的任意一个格子开始,每一步可以在矩阵中向左,向右,向上,向下移动一个格子.如果一条路径经过了矩 ...

  3. Spring Boot Actuator 整合 Prometheus

    简介 Spring Boot 自带监控功能 Actuator,可以帮助实现对程序内部运行情况监控,比如监控状况.Bean加载情况.环境变量.日志信息.线程信息等.这一节结合 Prometheus .G ...

  4. vc++中输入表的免杀

    国外的杀毒软件一般会把特征码定位在PE文件的输入表函数(也就是源码里我们调用了的API函数)上, 我们对付这种查杀的方法就是在源码里对API函数进行动态调用,对一个函数动态调用之后,本来以输入 表函数 ...

  5. MySQL 数据库的设计规范

    网址 :http://blog.csdn.net/yjjm1990/article/details/7525811 1.文档的建立日期.所属的单位.2.数据库的命名规范.视图.3.命名的规范:1)避免 ...

  6. JVM 中发生内存溢出的 8 种原因及解决办法

    1. Java 堆空间 2. GC 开销超过限制 3. 请求的数组大小超过虚拟机限制 4. Perm gen 空间 5. Metaspace 6. 无法新建本机线程 7. 杀死进程或子进程 8. 发生 ...

  7. std::this_thread::yield/sleep_for

    std::this_thread::yield(): 当前线程放弃执行,操作系统调度另一线程继续执行.. std::this_thread::sleep_for(): 表示当前线程休眠一段时间,休眠期 ...

  8. C#初始类和命名空间

    本节内容: 1.剖析Hello,World程序 1.1初始类(class)与名称空间(namespace) 2.类库的引用 2.1DLL的引用(黑盒引用) 2.2项目引用(白盒引用) 2.3建立自己的 ...

  9. Js极客之路 - 简化操作

    1.对字符串使用单引号(避免动态添加元素时html会出现的双引号"引起的冲突,方便操作 - 单引号一个键,双引号两个键) // bad var name = "Barrior&qu ...

  10. 设计模式(二十一)Proxy模式

    在面向对象编程中,“本人”和“代理人”都是对象.如果“本人”对象太忙了,有些工作无法自己亲自完成,就将其交给“代理人”对象负责. 示例程序的类图. 示例程序的时序图.从这个时序图可以看出,直到调用pr ...