Advertisement
Guest User

Task_21.03 (List)

a guest
Mar 21st, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <list>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     list<double> array;
  9.     double x;
  10.     int command;
  11.     cout << "Printf command: \n"
  12.          << "1 - if you want to enter number\n"
  13.          << "2 - if you want to delete number\n"
  14.          << "0 - if you want to finish program\n";
  15.     cin >> command;
  16.     while(command!=0){
  17.         if(command == 1){
  18.             int place;
  19.             auto it = array.begin();
  20.             double num;
  21.             cout << "Enter number and place you want to put it to\n";
  22.             cin >> num >> place;
  23.             if(place<0){
  24.                 cout << "ERROR: NO SUCH DIRECTORY\n";
  25.             }
  26.             else if(place>=array.size()+1){
  27.                 cout << "ERROR: NO SUCH DIRECTORY\n";
  28.             }
  29.             else {
  30.                 for(int i=0; i!= place; ++i){
  31.                     ++it;
  32.                 }
  33.                 array.insert(it, num);
  34.             }
  35.         }
  36.         else{
  37.             if(array.size()==0){
  38.                 cout << "ERROR: NO ELEMENTS TO DELETE\n";
  39.             }
  40.             else{
  41.                 int place;
  42.                 auto it = array.begin();
  43.                 cout << "Enter number of element you want to delete\n";
  44.                 cin >> place;
  45.                 if(place<0){
  46.                     cout << "ERROR: NO SUCH DIRECTORY\n";
  47.                 }
  48.                 else{
  49.                     for(int i=0; i!= place; ++i){
  50.                         ++it;
  51.                     }
  52.                     array.erase(it);
  53.                 }
  54.             }
  55.         }
  56.         for(auto i:array){
  57.             cout << i << " ";
  58.         }
  59.         cout << "\n";
  60.         cout << "Printf command: \n"
  61.              << "1 - if you want to enter number\n"
  62.              << "2 - if you want to delete number\n"
  63.              << "0 - if you want to finish program\n";
  64.         cin >> command;
  65.     }
  66.     return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement