Pagini recente » Cod sursa (job #731777) | Cod sursa (job #1838156) | Cod sursa (job #2052729) | Cod sursa (job #2227380) | Cod sursa (job #1439367)
#include <iostream>
#include <algorithm>
using namespace std;
class Coada{
public:
int x,t[101],st,n;
Coada(int d){
st = 1;
n = 0;
for(int i = 0; i <= d; ++i)
t[i] = 0;
}
inline int ls(){
return (n-st);
}
inline bool gol(){
if(st > n) return true;
return false;
}
inline void ad(int x){
int i,l,r,*p,poz;
if(t[n] <= x){
t[++n] = x;
return;
}
p = upper_bound(t+st,t+n+1,x);
poz = p-(t+st-1);
++n;
for(i = n; i > poz;--i)
t[i] = t[i-1];
t[poz] = x;
}
inline int top(){
return t[n];
}
inline int bot(){
return t[st];
}
inline void del_top(){
--n;
}
inline void del_bot(){
++st;
}
friend Coada &operator+(Coada &q,int x){
q.t[q.n]+=x;
return q;
}
friend Coada &operator-(Coada &q,int x){
int y;
y = q.t[q.n]-x;
q.del_top();
q.ad(y);
return q;
}
};
int main(){
Coada q(100);
q.ad(5);
q.ad(3);
return 0;
}