1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

vector

Last updated at Posted at 2022-02-21

vector< int > a;

a.push_back(x); (末尾に追加)

a.pop_back(); (末尾を削除)

a.size()

a.clear() (全ての要素を削除)

sort(a.begin(), a.end())
sort(a.begin() + l, a.begin() + r)

erase( 削除 )の使い方

 // (1)
  {
    std::vector<int> v = {1, 2, 3, 4, 5};

    v.erase(v.begin() + 2);
    print("(1)", v);
  }

  // (2)
  {
    std::vector<int> v = {1, 2, 3, 4, 5};

    v.erase(v.begin(), v.begin() + 2);
    print("(2)", v);
  }

  //a.end() = a.begin() + a.size() - 1
(1) : {1, 2, 4, 5}
(2) : {3, 4, 5}
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?