#reorder method

6 messages · Page 1 of 1 (latest)

slate drift
#

Here is my output
Reordered Queue by attribute 1:
Job ID: 101, Priority: 8, Job Type: 2, CPU Time Consumed: 150, Memory Consumed: 2000
Job ID: 105, Priority: 7, Job Type: 5, CPU Time Consumed: 220, Memory Consumed: 1024
Job ID: 106, Priority: 4, Job Type: 2, CPU Time Consumed: 320, Memory Consumed: 5120
Job ID: 102, Priority: 3, Job Type: 1, CPU Time Consumed: 100, Memory Consumed: 1024
Job ID: 104, Priority: 2, Job Type: 3, CPU Time Consumed: 300, Memory Consumed: 2048

need:
Reordered Queue by attribute 1:
Job ID: 101, Priority: 8, Job Type: 2, CPU Time Consumed: 150, Memory Consumed:
2000
Job ID: 102, Priority: 3, Job Type: 1, CPU Time Consumed: 100, Memory Consumed:
1024
Job ID: 104, Priority: 2, Job Type: 3, CPU Time Consumed: 300, Memory Consumed:
2048
Job ID: 105, Priority: 7, Job Type: 5, CPU Time Consumed: 220, Memory Consumed:
1024
Job ID: 106, Priority: 4, Job Type: 2, CPU Time Consumed: 320, Memory Consumed:
5120

south masonBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

slate drift
#

here is my code NovelQueue<DT>* reorder(int attribute_index) {
NovelQueue<DT>* newQueue = new NovelQueue<DT>();
newQueue->queue = queue;

    switch (attribute_index) {
        case 1:
            sort(newQueue->queue.begin(), newQueue->queue.end(), [](DT a, DT b) {
                if (a->priority == b->priority) {
                    return a->job_id < b->job_id;
                }
                return a->priority > b->priority;
            });
            break;
        case 2:
            sort(newQueue->queue.begin(), newQueue->queue.end(), [](DT a, DT b) {
                if (a->cpu_time_consumed == b->cpu_time_consumed) {
                    return a->job_id < b->job_id;
                }
                return a->cpu_time_consumed < b->cpu_time_consumed;
            });
            break;
        default:
            cout << "Invalid attribute index!" << endl;
            delete newQueue;
            return nullptr;
    }

    cout << "Reordered Queue by attribute " << attribute_index << ":" << endl;
    newQueue->displayJobsWithoutHeader();

    return newQueue;
}
south masonBOT
#
How to Format Code on Discord
Markup

```cpp
int main() {}
```

Result
int main() {}
wintry zealot
#

and

south masonBOT
#
How to Ask a Programming Question

Anyone can ask a question in our programming channels. Following the guide Writing The Perfect Question is recommended.

What to Post

State your problem clearly and provide all necessary details:

  • the relevant portion of your code, or all of it
  • the expected output
  • the actual output (or the full error)
    :trophy: Gold Standard: Minimal Reproducible Example
Where to Post

Provide the relevant code in the message, and format it nicely with a code block*. If it's too much for one message, you can upload it:

  • Compiler Explorer for most C and C++ snippets
  • OnlineGDB for interaction, debugging
    :no_entry: Do not post screenshots, let alone photos of your screen!