Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <list>
- #include <string>
- #include <vector>
- using namespace std;
- int main() {
- list<double> array;
- vector<list<double>::iterator> oper;
- int command, operation=0;
- cout << "Print command: \n"
- // << "1 - if you want to enter number\n"
- // << "2 - if you want to delete number\n"
- << "3 - if you want to enter number to the end\n"
- << "4 - if you want to delete number from X operation\n"
- << "5 - if you want to print array\n"
- << "0 - if you want to finish program\n";
- cin >> command;
- while(command!=0){
- if(command==3) {
- double num;
- int x=0;
- cout << "Enter number you want to push\n";
- cin >> num;
- array.push_back(num);
- /*auto it = array.begin();
- while(it!=array.end()){
- ++x;
- ++it;
- }
- oper.resize(oper.size()+1);*/
- oper.push_back(--array.end());
- ++operation;
- }
- else if(command==4){
- int X;
- cout << "Enter X\n";
- cin >> X;
- auto it = --array.begin();
- if(X>=oper.size()){
- cout << "ERROR\n";
- }
- else if(oper[X]!=it){
- array.erase(oper[X]);
- oper.push_back(--array.begin());
- ++operation;
- }
- else if(oper[X]==it){
- cout << "ERROR\n";
- }
- }
- else{
- for(auto c:array){
- cout << c << " ";
- }
- cout << "\n";
- oper.push_back(--array.begin());
- ++operation;
- }
- cout << "Print command: \n"
- << "3 - if you want to enter number to the end\n"
- << "4 - if you want to delete number from X operation\n"
- << "5 - if you want to print array\n"
- << "0 - if you want to finish program\n";
- cin >> command;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement