convert in C language

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

please help to convert in C language

//find index of nearest job which is
//non intersecting to curent job.
11 id = findi(v1, n);
//find profit by including current
//index profit.
11 pl = vi[n].pr + solve(v1, id);
//find profit by not including
//current index element.
11 p2 = solve(v1, n - 1);
//return maximum value.
return max(pl, p2);
int main()
11 t, st, en, pr;
cout « "Enter number of test cases: ";
cin >> t;
while (t--) {
cout « "Enter number of jobs: ";
11 n;
cin >> n;
vector<job> v1;
cout « "Enter job details:\n";
for (11 i = 0; i< n; i++) {
cin >> st > en >> pr;
v1.push_back({ st, en, pr });
//sort according to finish time.
sort(v1.begin(), v1.end(), fun);
cout « "Maximum profit: ";
cout « solve(v1, n - 1) « "\n";
return e;
Transcribed Image Text://find index of nearest job which is //non intersecting to curent job. 11 id = findi(v1, n); //find profit by including current //index profit. 11 pl = vi[n].pr + solve(v1, id); //find profit by not including //current index element. 11 p2 = solve(v1, n - 1); //return maximum value. return max(pl, p2); int main() 11 t, st, en, pr; cout « "Enter number of test cases: "; cin >> t; while (t--) { cout « "Enter number of jobs: "; 11 n; cin >> n; vector<job> v1; cout « "Enter job details:\n"; for (11 i = 0; i< n; i++) { cin >> st > en >> pr; v1.push_back({ st, en, pr }); //sort according to finish time. sort(v1.begin(), v1.end(), fun); cout « "Maximum profit: "; cout « solve(v1, n - 1) « "\n"; return e;
#include <bits/stdc++.h>
using namespace std;
typedef long 1ong 11;
//user defined job data type.
struct job { //start,end and profit.
11 st, en, pr;
};
//fun function for checking
// smallest of two job on basis
//of their finish time.
bool fun(const jobs j1, const jobk j2)
{
if (j1.en < j2.en)
return true;
else
return false;
//findi function using binary search
//it reduces the time complexity
11 find1(vectorcjob>& v1, 11 n)
//start variable for binary search.
11 st - 0;
//end variable for binary search.
11 en = n;
//search under range of binary
//search boundary.
while (st c en) {
//find mid index.
11 mid = st + (en - st) / 2;
//if mid index element has finish time less
//than equal to start time of nth index element.
if (vi[mid].en <= vi[n].st) {
if (vi[mid].en <= vi[n].st) {
//check for nrearest index to current
//nth element.
if (vi[mid + 1].en <= vi[n].st)
st = mid + 1;
else
return mid;
}
else //reduce search spaces.
en = mid - 1;
//if no other non intersecting job is found.
return -1;
//find function working in linear time.
11 find(vector<job>& v1, 1l n)
{
//iterate through all elements
//and check which job is non intersecting.
for (11 i = n - 1; i >= 0; i--) {
if (vi[i].en <= vi[n].st)
return i;
//if not found then return -1.
return -1;
//solve function which will return maximum
//profit.
11 solve(vectorcjob>& v1, 11 n)
//if one job is remaining.
if (n == 0)
return vi[n].pr;
//if index if out of bound.
if (n < 0)
return e;
Transcribed Image Text:#include <bits/stdc++.h> using namespace std; typedef long 1ong 11; //user defined job data type. struct job { //start,end and profit. 11 st, en, pr; }; //fun function for checking // smallest of two job on basis //of their finish time. bool fun(const jobs j1, const jobk j2) { if (j1.en < j2.en) return true; else return false; //findi function using binary search //it reduces the time complexity 11 find1(vectorcjob>& v1, 11 n) //start variable for binary search. 11 st - 0; //end variable for binary search. 11 en = n; //search under range of binary //search boundary. while (st c en) { //find mid index. 11 mid = st + (en - st) / 2; //if mid index element has finish time less //than equal to start time of nth index element. if (vi[mid].en <= vi[n].st) { if (vi[mid].en <= vi[n].st) { //check for nrearest index to current //nth element. if (vi[mid + 1].en <= vi[n].st) st = mid + 1; else return mid; } else //reduce search spaces. en = mid - 1; //if no other non intersecting job is found. return -1; //find function working in linear time. 11 find(vector<job>& v1, 1l n) { //iterate through all elements //and check which job is non intersecting. for (11 i = n - 1; i >= 0; i--) { if (vi[i].en <= vi[n].st) return i; //if not found then return -1. return -1; //solve function which will return maximum //profit. 11 solve(vectorcjob>& v1, 11 n) //if one job is remaining. if (n == 0) return vi[n].pr; //if index if out of bound. if (n < 0) return e;
Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY