Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. help please!

help please!

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsdata-structureshelpquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    ginjikun
    wrote on last edited by
    #1

    hi! i would like to ask what is the best way to store and sort (e.g. priority queue,multimap,sorted vector, etc) my date which consist of 2 criterias. first is the priority, then according to group. sample is... priority 1, group1 data 1 data 2 priority 1, group 2 data 1 data 2 data 3 priority 2, group 4 data 1 group 5 data 1 ... each group may consist of 1 or more data i was thinking of priority_queue however some of the data are stored til the end of the application. i am not sure if queue have somekind of peek method. and vector using sort method, but the data are added throughout the lifetime of the application indefinitely and not just 1 time... sort may be too expensive to be called many times. thanks for any help! newbie :)

    Y 1 Reply Last reply
    0
    • G ginjikun

      hi! i would like to ask what is the best way to store and sort (e.g. priority queue,multimap,sorted vector, etc) my date which consist of 2 criterias. first is the priority, then according to group. sample is... priority 1, group1 data 1 data 2 priority 1, group 2 data 1 data 2 data 3 priority 2, group 4 data 1 group 5 data 1 ... each group may consist of 1 or more data i was thinking of priority_queue however some of the data are stored til the end of the application. i am not sure if queue have somekind of peek method. and vector using sort method, but the data are added throughout the lifetime of the application indefinitely and not just 1 time... sort may be too expensive to be called many times. thanks for any help! newbie :)

      Y Offline
      Y Offline
      Y_Kaushik
      wrote on last edited by
      #2

      Explain in deatail.... What is your actual requirment I thnink your question is incomplete

      Regard's Kaushik

      G 1 Reply Last reply
      0
      • Y Y_Kaushik

        Explain in deatail.... What is your actual requirment I thnink your question is incomplete

        Regard's Kaushik

        G Offline
        G Offline
        ginjikun
        wrote on last edited by
        #3

        Hi Kaushik thanks for the response! the requirement is to store according to priority and group each of the data that are received.... receiving of data happens indefinitely (e.g. every 1 second/5seconds) each data as mentioned should be arranged according to their priority and group they belong. thus the list should look something like below priority 1 group 1 data 1 data 2 group 2 data 1 group 3 data 1 data 2 priority 2 group 4 data 1 group 5 data 1 data 2 ... the group number is unique, thus there can only be a single group 1 in the entire list... and so on... the question is how to efficiently implement this. keeping in mind that the data coming in may occur every second or maybe less... also the data are stored indefinitely depending on the priority.. e.g. priority 1 may be removed after processing but priority 2 after processing will stil remain in the list... sorry for the lenghty explanation... thanks again for any response! newbie :)

        S 1 Reply Last reply
        0
        • G ginjikun

          Hi Kaushik thanks for the response! the requirement is to store according to priority and group each of the data that are received.... receiving of data happens indefinitely (e.g. every 1 second/5seconds) each data as mentioned should be arranged according to their priority and group they belong. thus the list should look something like below priority 1 group 1 data 1 data 2 group 2 data 1 group 3 data 1 data 2 priority 2 group 4 data 1 group 5 data 1 data 2 ... the group number is unique, thus there can only be a single group 1 in the entire list... and so on... the question is how to efficiently implement this. keeping in mind that the data coming in may occur every second or maybe less... also the data are stored indefinitely depending on the priority.. e.g. priority 1 may be removed after processing but priority 2 after processing will stil remain in the list... sorry for the lenghty explanation... thanks again for any response! newbie :)

          S Offline
          S Offline
          Stephen Hewitt
          wrote on last edited by
          #4

          Perhaps this will give you some ideas: -------------------------------------- // Console.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include #include #include #include #include class CData { public: CData(int priority, int group) : priority_(priority) , group_(group) {} // Define the sorting criteria. friend bool operator<(const CData &l, const CData &r) { if (l.priority_ inline std::basic_ostream& operator<<(std::basic_ostream &os, const CData &d) { os << "Priority: " << d.priority_ << std::endl; os << "Group: " << d.group_ << std::endl; return os; } typedef std::set DataCollecton_t; int main(int arvc, char* argv[]) { // Populate the collection. DataCollecton_t coll; coll.insert(CData(3, 2)); coll.insert(CData(3, 3)); coll.insert(CData(2, 2)); coll.insert(CData(1, 1)); coll.insert(CData(2, 3)); coll.insert(CData(1, 2)); coll.insert(CData(2, 1)); coll.insert(CData(1, 3)); coll.insert(CData(3, 1)); // Print the results. std::copy(coll.begin(), coll.end(), std::ostream_iterator(std::cout)); return 0; } Steve

          G 1 Reply Last reply
          0
          • S Stephen Hewitt

            Perhaps this will give you some ideas: -------------------------------------- // Console.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include #include #include #include #include class CData { public: CData(int priority, int group) : priority_(priority) , group_(group) {} // Define the sorting criteria. friend bool operator<(const CData &l, const CData &r) { if (l.priority_ inline std::basic_ostream& operator<<(std::basic_ostream &os, const CData &d) { os << "Priority: " << d.priority_ << std::endl; os << "Group: " << d.group_ << std::endl; return os; } typedef std::set DataCollecton_t; int main(int arvc, char* argv[]) { // Populate the collection. DataCollecton_t coll; coll.insert(CData(3, 2)); coll.insert(CData(3, 3)); coll.insert(CData(2, 2)); coll.insert(CData(1, 1)); coll.insert(CData(2, 3)); coll.insert(CData(1, 2)); coll.insert(CData(2, 1)); coll.insert(CData(1, 3)); coll.insert(CData(3, 1)); // Print the results. std::copy(coll.begin(), coll.end(), std::ostream_iterator(std::cout)); return 0; } Steve

            G Offline
            G Offline
            ginjikun
            wrote on last edited by
            #5

            Hi Steve! thanks for the reply! im sure your post will give me some idea and help me great deal. thanks again! newbie :)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups