STL.h
最近老是被系统的一些STL卡到飞起,然后就手打了一个STL.h 库函数还没有打完,以后打新的还会再更,大家也可以使用,顺便帮我找一下bug,然后我再改进!
- template< typename RT >class queue
- {
- public:
- RT sta[];
- int l,r;
- void clear(){l=r=;}
- inline void push(RT x){sta[r++]=x;return ;}
- inline void pop(){l++;return ;}
- inline RT front(){return sta[l];}
- inline bool empty(){return r==l;}
- inline bool size(){return r!=l;}
- };
- template< typename RT >class stack
- {
- public:
- RT sta[];
- int topp;
- void clear(){topp=;}
- inline void push(RT x){sta[++topp]=x;return ;}
- inline void pop(){topp--;return ;}
- inline bool empty(){return topp==;}
- inline bool size(){return topp;}
- inline bool top(){return sta[topp];}
- };
- template< typename RT >class hash_table
- {
- public:
- int mod;
- inline void init(int x){mod=x;return ;}
- int head[],vvt[],nxt[],tot;
- RT ver[];
- inline void insert(int x,RT ac)
- {
- int u=x%mod;
- for(int i=head[u];i;i=nxt[i])
- {
- RT y=ver[i];
- if(y==ac){vvt[i]++;return ;}
- }
- ver[++tot]=ac;
- nxt[tot]=head[u];
- head[u]=tot;
- vvt[tot]++;
- }
- inline int query_times(int x,RT ac)
- {
- int u=x%mod;
- for(int i=head[u];i;i=nxt[i])
- {
- RT y=ver[i];
- if(y==ac)return vvt[i];
- }
- return ;
- }
- };
//////未完/////////
2019.9.23 UPDATE
更新了queue和stack的大小参数和一些骚操作!
hash_table 没有更新!
- //#include<iostream>
- //#include<cstdio>
- //#include<cstdlib>
- //#include<algorithm>
- //using namespace std;
- //make by lsc; %%%stl
- template<typename RT,int MAXN>
- class stack
- {
- public:
- RT sta[MAXN];int topp;
- inline void clear(){topp=;return ;}
- inline void init(){topp=;return ;}
- inline void push(RT x){sta[++topp]=x;return ;}
- inline int size(){return topp;}
- inline bool empty(){return topp;}
- inline int bottom(){if(topp==)return -(<<);else return sta[];}
- inline int num(RT x){return sta[x];}
- inline void sort_stack(RT x){sort(sta+,sta+topp+);if(x)return ;else reverse(sta+,sta+topp+);return ;}//如果x==1,从小到大,else less;
- /*
- if struct sort please make function!
- */
- };
- template<typename RT,int MAXN>
- class queue
- {
- public:
- #define re register
- RT sta[MAXN];
- int fr,back;
- inline void init(){fr=;back=;}
- inline void push(re RT x){sta[++back]=x;return ;}
- inline void pop(){fr++;return ;}
- inline RT front(){return sta[fr];}
- inline bool empty(){if(back>=fr)return ;else return ;}
- inline bool size(){if(back<=fr)return ;else return ;}
- inline void sort_queue(RT x){sort(sta+back,sta+fr+);if(x)return ;else reverse(sta+back,sta+fr+);return ;}
- };
UPDATE 新版本!
- /*
- #include<iostream>
- #include<cstdio>
- #include<cstdlib>
- #include<algorithm>
- using namespace std;
- */
- //make by lsc; %%%stl
- template<typename RT,int MAXN>
- class stack
- {
- public:
- RT sta[MAXN];int topp;
- inline void clear(){topp=;return ;}
- inline void init(){topp=;return ;}
- inline void push(RT x){sta[++topp]=x;return ;}
- inline int size(){return topp;}
- inline bool empty(){return topp;}
- inline int bottom(){if(topp==)return -(<<);else return sta[];}
- inline int num(RT x){return sta[x];}
- inline void pop(){topp--;if(topp<)topp=;return ;}
- inline void sort_stack(RT x){sort(sta+,sta+topp+);if(x)return ;else reverse(sta+,sta+topp+);return ;}//如果x==1,从小到大,else less;
- /*
- if struct sort please make function!
- */
- };
- template<typename RT,int MAXN>
- class queue
- {
- public:
- #define re register
- RT sta[MAXN];
- int fr,back;
- inline void init(){fr=;back=;}
- inline void push(re RT x){sta[++back]=x;return ;}
- inline void pop(){fr++;return ;}
- inline RT front(){return sta[fr];}
- inline bool empty(){if(back>=fr)return ;else return ;}
- inline bool size(){if(back<=fr)return ;else return ;}
- inline void sort_queue(RT x){sort(sta+back,sta+fr+);if(x)return ;else reverse(sta+back,sta+fr+);return ;}
- };
- template<typename RT,int MAXN>
- class priority_queue
- {
- public:
- RT q[MAXN];int sz;
- priority_queue(){sz=;}
- inline void push(int x)
- {
- q[++sz]=x;
- for(int i=sz,j=i>>;j;i=j,j>>=)
- if(q[j]>q[i])swap(q[j],q[i]);
- }
- inline void pop()
- {
- q[]=q[sz--];
- for(int i=,j=i<<;j<=sz;i=j,j<<=)
- {
- if((j|)<=sz&&q[j|]<q[j])j=j|;
- if(q[i]>q[j])swap(q[i],q[j]);
- else break;
- }
- }
- inline RT top(){return q[];}
- };
- //UPDATE 2019.9.23 pair 未经过测试!
- template<typename RT,typename RE>
- class pair
- {
- public:
- RT first;RE second;
- pair(){first=,second=;}
- inline void make_pair(RT a,RE b){first=a,second=b;return ;}
- /*
- THIS FUNCTION THE DIRECTOR DIDN'T TRUST IT ,SO THE THINGS AFTER YOU USE IT ONLY YOU BEAR!
- */
- };
UPDATE 2019.9.26 整理了一下,但没有测试!
- /*
- #include<iostream>
- #include<cstdio>
- #include<cstdlib>
- #include<algorithm>
- using namespace std;
- */
- //make by lsc; %%%stl
- template<typename RT,int MAXN>
- class stack
- {
- public:
- RT sta[MAXN];int topp;
- inline void clear(){topp=;return ;}
- inline void init(){topp=;return ;}
- inline void push(RT x){sta[++topp]=x;return ;}
- inline int size(){return topp;}
- inline bool empty(){return topp;}
- inline int bottom(){if(topp==)return -(<<);else return sta[];}
- inline int num(RT x){return sta[x];}
- inline void pop(){topp--;if(topp<)topp=;return ;}
- inline void sort_stack(RT x){sort(sta+,sta+topp+);if(x)return ;else reverse(sta+,sta+topp+);return ;}//如果x==1,从小到大,else less;
- /*
- if struct sort please make function!
- */
- };
- template<typename RT,int MAXN>
- class queue
- {
- public:
- #define re register
- RT sta[MAXN];
- int fr,back;
- inline void init(){fr=;back=;}
- inline void push(re RT x){sta[++back]=x;return ;}
- inline void pop(){fr++;return ;}
- inline RT front(){return sta[fr];}
- inline bool empty(){if(back>=fr)return ;else return ;}
- inline bool size(){if(back<=fr)return ;else return ;}
- inline void sort_queue(RT x){sort(sta+back,sta+fr+);if(x)return ;else reverse(sta+back,sta+fr+);return ;}
- };
- template<typename RT,int MAXN>
- class priority_queue
- {
- public:
- RT q[MAXN];int sz;
- priority_queue(){sz=;}
- inline void push(int x)
- {
- q[++sz]=x;
- for(int i=sz,j=i>>;j;i=j,j>>=)
- if(q[j]>q[i])swap(q[j],q[i]);
- }
- inline void pop()
- {
- q[]=q[sz--];
- for(int i=,j=i<<;j<=sz;i=j,j<<=)
- {
- if((j|)<=sz&&q[j|]<q[j])j=j|;
- if(q[i]>q[j])swap(q[i],q[j]);
- else break;
- }
- }
- inline RT top(){return q[];}
- };
- //UPDATE 2019.9.23 pair 未经过测试!
- template<typename RT,typename RE>
- class pair
- {
- public:
- RT first;RE second;
- pair(){first=,second=;}
- inline void make_pair(RT a,RE b){first=a,second=b;return ;}
- /*
- THIS FUNCTION THE DIRECTOR DIDN'T TRUST IT ,SO THE THINGS AFTER YOU USE IT ONLY YOU BEAR!
- */
- };
- template< typename RT >class hash_table
- {
- public:
- int mod;
- inline void init(int x){mod=x;return ;}
- int head[],vvt[],nxt[],tot;
- RT ver[];
- inline void insert(int x,RT ac)
- {
- int u=x%mod;
- for(int i=head[u];i;i=nxt[i])
- {
- RT y=ver[i];
- if(y==ac){vvt[i]++;return ;}
- }
- ver[++tot]=ac;
- nxt[tot]=head[u];
- head[u]=tot;
- vvt[tot]++;
- }
- inline int query_times(int x,RT ac)
- {
- int u=x%mod;
- for(int i=head[u];i;i=nxt[i])
- {
- RT y=ver[i];
- if(y==ac)return vvt[i];
- }
- return ;
- }
- };
- //2019.9.26 UPDATE
- //lower_bound but didn't test ,you can test it ,but not int exam!
- //I dont't konw if it has bugs!
- template<typename RT,typename RE>
- RE lower_bound(RT *a,RE l,RE r)
- {
- while(l<r)
- {
- int mid=(l+r)>>;
- if(a[mid]>=r)r=mid;
- else l=mid+;
- }
- return l;
- };
STL.h的更多相关文章
- 在查找预编译头时遇到意外的文件结尾。是否忘记了向源中添加“#include "StdAfx.h"”?
在查找预编译头时遇到意外的文件结尾.是否忘记了向源中添加“#include "StdAfx.h"”? 右键选择该文件.cpp格式的->属性->预编译头,→ 不使用预编译 ...
- STLtoSVG,and SVG to Bmp
先用这两个工具: Slic3R或者Skeinforge:这个两个工具的作用就是把STL文件切片为叠加的矢量图(SVG格式) 因为SVG是分层的,一层一层的把每层都转换成一张Bmp文件 听说ImageM ...
- C++客户端访问WebService VS2008
VS2008及之后的版本已经不支持使用C++开发WEBService服务了,如果要在VS上开发WEBService,需要使用C#开发语言. 一.gSOAP简介 gSOAP编译工具提供了一个基于SOAP ...
- 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 ...
- 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 ...
- VS2015 dlib编译 x64 Release .lib生成
VS2015 dlib编译 x64 Release >------ 已启动生成: 项目: ZERO_CHECK, 配置: Release x64 ------ > Checking Bui ...
- VS2015 dlib编译 x64 Debug .lib生成
VS2015 dlib编译 x64 Debug >------ 已启动生成: 项目: ZERO_CHECK, 配置: Debug x64 ------ > Checking Build S ...
- JMeter接口测试印象篇(win10)
参考博文1:https://www.cnblogs.com/suim1218/p/9257369.html 参考博文2:https://blog.csdn.net/u011541946/article ...
- 混合编程:如何用python11调用C++
摘要:在实际开发过程中,免不了涉及到混合编程,比如,对于python这种脚本语言,性能还是有限的,在一些对性能要求高的情景下面,还是需要使用c/c++来完成. 那怎样做呢?我们能使用pybind11作 ...
随机推荐
- mac下ip地址重定向
在终端临时使用最高权限用vim编辑/etc下的hosts文件,若提示Password: 输入开机登录密码并回车: yanguobindeMacBook-Pro:~ yanguobin$ sudo vi ...
- 算法学习之剑指offer(十二)
一 题目描述 请设计一个函数,用来判断在一个矩阵中是否存在一条包含某字符串所有字符的路径.路径可以从矩阵中的任意一个格子开始,每一步可以在矩阵中向左,向右,向上,向下移动一个格子.如果一条路径经过了矩 ...
- Spring Boot Actuator 整合 Prometheus
简介 Spring Boot 自带监控功能 Actuator,可以帮助实现对程序内部运行情况监控,比如监控状况.Bean加载情况.环境变量.日志信息.线程信息等.这一节结合 Prometheus .G ...
- vc++中输入表的免杀
国外的杀毒软件一般会把特征码定位在PE文件的输入表函数(也就是源码里我们调用了的API函数)上, 我们对付这种查杀的方法就是在源码里对API函数进行动态调用,对一个函数动态调用之后,本来以输入 表函数 ...
- MySQL 数据库的设计规范
网址 :http://blog.csdn.net/yjjm1990/article/details/7525811 1.文档的建立日期.所属的单位.2.数据库的命名规范.视图.3.命名的规范:1)避免 ...
- JVM 中发生内存溢出的 8 种原因及解决办法
1. Java 堆空间 2. GC 开销超过限制 3. 请求的数组大小超过虚拟机限制 4. Perm gen 空间 5. Metaspace 6. 无法新建本机线程 7. 杀死进程或子进程 8. 发生 ...
- std::this_thread::yield/sleep_for
std::this_thread::yield(): 当前线程放弃执行,操作系统调度另一线程继续执行.. std::this_thread::sleep_for(): 表示当前线程休眠一段时间,休眠期 ...
- C#初始类和命名空间
本节内容: 1.剖析Hello,World程序 1.1初始类(class)与名称空间(namespace) 2.类库的引用 2.1DLL的引用(黑盒引用) 2.2项目引用(白盒引用) 2.3建立自己的 ...
- Js极客之路 - 简化操作
1.对字符串使用单引号(避免动态添加元素时html会出现的双引号"引起的冲突,方便操作 - 单引号一个键,双引号两个键) // bad var name = "Barrior&qu ...
- 设计模式(二十一)Proxy模式
在面向对象编程中,“本人”和“代理人”都是对象.如果“本人”对象太忙了,有些工作无法自己亲自完成,就将其交给“代理人”对象负责. 示例程序的类图. 示例程序的时序图.从这个时序图可以看出,直到调用pr ...