Skip to content

Commit 5ba6078

Browse files
New Commit
1 parent e13e6ac commit 5ba6078

File tree

2 files changed

+1
-83
lines changed

2 files changed

+1
-83
lines changed

job_scheduling.c

Lines changed: 1 addition & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
<<<<<<< HEAD
21
#include<stdio.h>
32

43
int p[100], jobs, d[100], final_dead[100];
@@ -51,7 +50,7 @@ void jobSelection(){
5150

5251
int profit = 0; //Stores the maximum profit
5352

54-
for(i=0;i<max;i++)
53+
for(i=0;i<=max;i++)
5554
final_dead[i] = 0;
5655

5756
for(i=max;i>=0;i--){
@@ -78,85 +77,4 @@ int main(){
7877
input();
7978
jobSelection();
8079
return 0;
81-
=======
82-
#include<stdio.h>
83-
84-
int p[100], jobs, d[100], final_dead[100];
85-
86-
void input(){
87-
printf("Enter the profits and deadlines\n\n");
88-
for(int i=0;i<jobs;i++){
89-
printf("Job %d\n", i+1);
90-
printf("Profit : ");
91-
scanf("%d", &p[i]);
92-
printf("Deadline : ");
93-
scanf("%d", &d[i]);
94-
}
95-
printf("\n");
96-
}
97-
98-
void sort(){
99-
int i, j, t1, t2;
100-
for(i=0;i<jobs-1;i++){
101-
for(j=0;j<jobs-1-i;j++){
102-
if(p[j]<p[j+1]){
103-
t1 = p[j];
104-
t2 = d[j];
105-
106-
p[j] = p[j+1];
107-
d[j] = d[j+1];
108-
109-
p[j+1] = t1;
110-
d[j+1] = t2;
111-
}
112-
}
113-
}
114-
}
115-
116-
void jobSelection(){
117-
sort();
118-
int i, j;
119-
printf("Profit Array: ");
120-
for(i=0;i<jobs;i++){
121-
printf("%d ", p[i]);
122-
}
123-
124-
printf("\nDeadlines: ");
125-
for(i=0;i<jobs;i++)
126-
printf("%d ", d[i]);
127-
128-
int max = d[0];
129-
for(i=0;i<jobs;i++)
130-
if(d[i]>max) max = d[i];
131-
132-
int profit = 0; //Stores the maximum profit
133-
134-
for(i=0;i<max;i++)
135-
final_dead[i] = 0;
136-
137-
for(i=max;i>=0;i--){
138-
if(final_dead[i]!=0)
139-
continue;
140-
else{
141-
//Searching for the deadline index in array d
142-
for(j=0;j<jobs;j++){
143-
if(d[j]==i){
144-
final_dead[i] = p[j]; //Store the profits in the final deadline list
145-
profit += p[j];
146-
break;
147-
}
148-
}
149-
}
150-
}
151-
printf("\nMaximum Profit = %d\n", profit);
152-
153-
}
154-
155-
int main(){
156-
printf("Enter number of jobs: ");
157-
scanf("%d", &jobs);
158-
input();
159-
jobSelection();
160-
return 0;
161-
>>>>>>> a9b6520f1aa074c45bc777fd42beb569ca960413
16280
}

job_scheduling.exe

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)