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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:23:03+00:00 2026-06-12T13:23:03+00:00

I have a vector of structs, with the structs looking like this: struct myData{

  • 0

I have a vector of structs, with the structs looking like this:

struct myData{
    int ID;
    int arrivalTime;
    int burstTime;
};

After populating my vector with this data:

1 5 16
4 7 12
3 12 4
2 7 8

where each row is an individual struct’s ID (arbitrary, doesn’t denote order of arrival), arrivalTime and burstTime, how would I use “for” or “while” loops to step through my vector’s indices and calculate the data in a way that I could print something like this out?

Time 0  Processor is Idle
Time 5 Process 1 starts running
Time 21 Process 2 is running
Time 29 Process 4 is running
Time 41 Process 3 is running

The way I thought I could do it was to have an integer keep track what the current time is (the current time being the sum of the burst times of processes that have already ran) but I can’t seem to figure out an algorithm that accounts for Idle time (when the processor is not doing anything and a new task hasn’t arrived yet) as well as keeping track of the other numbers as well. For simplicity’s sake I just decided that when two processes arrive at the same time I would process the one with the lower ID number. I know I didn’t put much code here to demonstrate what I’m trying to do, but I hope I’ve explained it fairly clearly. I’m looking for a psuedo-code algorithm solution to this problem, but I wouldn’t say no to something that has been coded (In C++?).

As an additional note, in case I wasn’t able to convey how I access my data clearly, this:

cout << structVector[0].ID << "\n";
cout << structVector[0].arrivalTime << "\n";
cout << structVector[0].burstTime << "\n";

would print out

1
5
16

Any help in psuedo-code or actual code would be GREATLY appreciated!!! After reading this post over a few times I realize I’ve been pretty generic with the question, but I would love some help just understanding how to calculate this data.

  • 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-12T13:23:05+00:00Added an answer on June 12, 2026 at 1:23 pm

    First, sort the vector based on arrival times.
    Then the following code will accomplish what you are looking for.

    int i = 0, time = 0;
    
    while (i < vec.size())
    {
    if (vec[i]. arrivalTime > time)
    cout << "Time " << time << "process is idle";
    
    time += vec[i].arrivalTime;
    cout << "Time " << time << " Process " << vec[i].ID << " is running" << endl;
    
    time += vec[i].burstTime;
    
    i++;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

OK so I have a C++ function with a header like this: int myfunc(vector<int>
What I have: Vectors of different custom structs(one custom struct per vector) I used
I have a struct that looks like this: typedef struct _my_struct { float first_vector[SOME_NUM][OTHER_NUM];
I have a vector where I keep an incrementing data. Normally each element of
I have 2 matrix structs means equal data but have different form like these:
I have structs, let's call them sn, that look like: struct sn { string
I have a std::vector<Word> data that is off of the struct below: struct Word
I have a vector of structs, like so: std::vector<mystruct> elems . If I then
I have the following code: #include <iostream> #include <vector> using namespace std; struct A{};
I have vector< pair<int, int>> myVec (N); I want to have all pairs initialized

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.