STL.h
2024-09-01 16:30:39
最近老是被系统的一些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;
};
最新文章
- Child <;- many-to-one ->;Parent
- Android按需添加Google Play服务
- SWFUpload简介及中文参考手册(share)
- 在yii2验证之前执行一些额外自定义验证
- 【转】WordPress转PHPCMS策略-数据库完美转换
- do-while语句
- ssh连接慢的问题的解决?
- Magento修改邮件模板内容
- iostream/fstream中的输入输出流指针的绑定,tie函数的使用。
- 修改docker默认172.17网段
- .net中用到的一些方法
- json介绍及简单示例
- php过滤提交数据 防止sql注入攻击
- ajaxFileUpload只能上传一次,和上传同名图片不能上传等bug问题
- 项目实战02:nginx 反向代理负载均衡、动静分离和缓存的实现
- [转载]String.Empty、string=”” 和null的区别
- Oracle 导出错误 EXP-00000~EXP-00107
- bzoj 1188
- ASP.NET MVC:4 Ways To Prevent Duplicate Form Submission(转载)
- iptable 限制ip访问