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 8316253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:19:16+00:00 2026-06-08T21:19:16+00:00

I am using a map structure in my program. The key for the structure

  • 0

I am using a map structure in my program. The key for the structure is the timestamp. The values keep on changing randomly. My main intention of using map was to ensure that the representation of all the values along with their timestamp should be in the descending order, like the latest event should come on top. However, this is not happening. The values are not in the desired (descending) order.

I have declared map structure like

map<time_t, events> eventR;
map<time_t, events>::iterator iterator;

if the events are there {
then iterator=eventR.begin();
for(iterator = eventR.begin(); iterator!=eventR.end(); ++iterator)
{
//Display
}
}

It may be that I have understood map structure wrong, like it doesn’t sort necessarily, but I thought if I am using timestamp, so data will be displayed according to latest events. Am I doing something wrong here? Do I have to use different data structure to get desired result?

Thanks

  • 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-06-08T21:19:17+00:00Added an answer on June 8, 2026 at 9:19 pm

    Declare your map as: std::map<time_t, events, std::greater<time_t>>. (Use a typedef so that it’s easier to declare iterators.)

    Alternatively, iterate your map in reverse using rbegin() and rend().

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

Sidebar

Related Questions

I want to sort elements in map container using only values not key. how
Iam using structure map for resolving my dependencies, however i have a rather special
I'm using Structure map and want to inject instance (constructed by container) into controller's
I'm using the STL map data structure, and at the moment my code first
Im using the following structure: hash_map<string, list<time_t>> When I initially fill the hash map
I have this table structure and would like to map it using Fluent Hibernate
I'm using mod_rewrite to map my old directory structure to a new one. I
I have a program that load data from a file using std::ifstream and store
I have the following map structure: std::map<std::pair<int, char>, int> transitions; That represent the transition
I have an MVC controller that has a single constructor, I am using structure

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.