Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6135305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:27:47+00:00 2026-05-23T17:27:47+00:00

Ok, I have a vector< vector < long >> , and I want to

  • 0

Ok, I have a vector< vector < long >>, and I want to sort the innermost vectors from smallest to largest – i.e. I expect to have sorted vector < long > looking like 3,7,21 when sorted.

This has been asked before, but I want to do this very simply so that non-programmers can understand. I’ve seen that I can create a function or functor to sort as in this question. Is there a way to do this without creating an extra sorting function? I’m doing this as part of a class, and I’m hoping for a way to do this without having to have people hunting all over my code for the simple sorting function.

One possibility is that there may be some way to define the sorting function inside the class function, but this may not be allowed in C++.

Getting back to the point: I’ve seen several ways to do this, I’m wondering what the simplest way(s) are to sort a vector of integers. Any help is greatly appreciated, as this will probably help out much more than it may seem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:27:47+00:00Added an answer on May 23, 2026 at 5:27 pm

    If you want only the internal vectors sorted, then you can simply use the default sorting order:

    #include <algorithm>
    #include <vector>
    using namespace std;
    
    int main()
    {
        vector<vector<long>> v;
        for (auto i = v.begin(); i != v.end(); ++i)
            sort(i->begin(), i->end());
        return 0;
    }
    

    This example uses the latest version of the standard. An example for older C++ compilers would be a little more verbose.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a vector that I want to insert into a set . This
I have with two fields: long nr and a vector of long like below:
I have a vector-like class that contains an array of objects of type T
I have a vector of integers and I want to convert it to a
I have a vector of beans that holds information I want to display in
I have a vector of booleans. I need to set its elements from n-th
I want to create a vector which runs from 1 to 260 with increments
I have a class like this : import java.io.*; import java.util.*; public class Contact_Info_Entry
I have a long vector x, and another v, which contains lengths. I would
This is a relatively long post. F# has a matrix and vector type(in PowerPack

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.