Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <list>
- #include <string>
- using namespace std;
- int main() {
- list<double> array;
- double x;
- int command;
- cout << "Printf command: \n"
- << "1 - if you want to enter number\n"
- << "2 - if you want to delete number\n"
- << "0 - if you want to finish program\n";
- cin >> command;
- while(command!=0){
- if(command == 1){
- int place;
- auto it = array.begin();
- double num;
- cout << "Enter number and place you want to put it to\n";
- cin >> num >> place;
- if(place<0){
- cout << "ERROR: NO SUCH DIRECTORY\n";
- }
- else if(place>=array.size()+1){
- cout << "ERROR: NO SUCH DIRECTORY\n";
- }
- else {
- for(int i=0; i!= place; ++i){
- ++it;
- }
- array.insert(it, num);
- }
- }
- else{
- if(array.size()==0){
- cout << "ERROR: NO ELEMENTS TO DELETE\n";
- }
- else{
- int place;
- auto it = array.begin();
- cout << "Enter number of element you want to delete\n";
- cin >> place;
- if(place<0){
- cout << "ERROR: NO SUCH DIRECTORY\n";
- }
- else{
- for(int i=0; i!= place; ++i){
- ++it;
- }
- array.erase(it);
- }
- }
- }
- for(auto i:array){
- cout << i << " ";
- }
- cout << "\n";
- cout << "Printf command: \n"
- << "1 - if you want to enter number\n"
- << "2 - if you want to delete number\n"
- << "0 - if you want to finish program\n";
- cin >> command;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement