-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector.cpp
More file actions
36 lines (30 loc) · 695 Bytes
/
vector.cpp
File metadata and controls
36 lines (30 loc) · 695 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include<vector>
#include<iostream>
using namespace std;
struct point{int x;int z;};
vector<point> datas;
int oldest_ind=0,newest_ind=0;
int window=50;
void addd(point p)
{
if(datas.size()<window)
datas.push_back(p);
else
{newest_ind = oldest_ind;datas[oldest_ind++]=p;}
newest_ind=oldest_ind-1;
if(oldest_ind==window) {newest_ind=window-1;oldest_ind=0;}
}
int main()
{
for(int i=0;i<101;i++)
{
struct point p;
p.x =i;p.z=100;
addd(p);
}
std::cout<<datas.size()<<endl;
for(int i=0 ; i<datas.size();i++)
std::cout<<datas[i].x<<",";
std::cout<<endl<<datas[oldest_ind].x<<endl;//ind the oldest one , (ind-1) the newest one
std::cout<<endl<<datas[newest_ind].x<<endl;
}