首页 技术 正文
技术 2022年11月9日
0 收藏 596 点赞 3,465 浏览 5944 个字

最近老是被系统的一些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;
};
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,492
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,494
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,132
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,295