Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- const int s = 100000;
- int d [s], f, l;
- int r_i (int i){
- return ((i%s +s)%s);
- }
- void push_front (int x){
- d [r_i(f)] = x;
- --f;
- cout << "ok" << endl;
- }
- void push_back (int x){
- d [r_i(l)] = x;
- ++l;
- cout << "ok" << endl;
- }
- int pop_front (int x){
- return (r_i(f));
- f++;
- }
- int pop_back (){
- return (r_i(l));
- --l;
- }
- int back (){
- return (d[r_i(l-1)]);
- }
- int front (){
- return (d[r_i(f+1)]);
- }
- int size (){
- return (l-f-1);
- }
- bool empty (){
- return (size() == 0);
- }
- void clear (){
- while (!empty){
- pop_back;
- }
- cout <<"ok"<< endl;
- }
- void exit(){
- cout <<"bye"<<endl;
- }
- int main(){
- string b;
- int a, c, d, e, f;
- while true{
- cin >> n;
- switch n:
- case ("push_front")
- {
- cin >> a;
- push_front (a)
- }
- case ("push_back")
- {
- cin >> c;
- push_back (c)
- }
- case ("push_front")
- {
- cin >> d;
- push_front (d)
- }
- case ("pop_front")
- {
- pop_front ()
- }
- case ("pop_back")
- {
- pop_back ()
- }
- case ("back")
- {
- cout<<back;
- }
- case ("front")
- {
- cout<<front;
- }
- case ("exit")
- {
- exit ()
- }
- case ("clear")
- {
- cin >> a;
- push_front (a)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement