The BOTTOM LINE Quote Of The Day

The BOTTOM LINE Quote Of The Day

Don't Ever Tell GOD How BIG Your Problems are.
Just Tell Your Problems How BIG your GOD is ;)

Saturday, May 5, 2012

Job Sequencing Problem 2


#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
struct jobs
{
                intid,deadl,profit;
}j[10],jf[10],temp;
void sort(int count)
{
                inti,k;
                for(i=0;i<count;i++)
                {
                                for(k=0;k<count-(i+1);k++)
                                {
                                                if(j[k].profit<j[k+1].profit)
                                                {
                                                                temp=j[k];
                                                                j[k]=j[k+1];
                                                                j[k+1]=temp;
                                                }
                                }             
                }
}
intgetpos(int index)
{
                int i=index-1;
                while(i>=0)
                {
                                if(jf[i].id==0)
                                return i;
                                i--;
                }
                return -1;                            
}
int main()
{
                inti,k,count,jfcount=0;
                printf("Count : ");
                scanf("%d",&count);
                fflush(stdin);
                for(i=0;i<count;i++)
                {
                printf("Enter details of %d job : ",i+1);
                scanf("%d %d %d",&j[i].id,&j[i].deadl,&j[i].profit);
                jf[i].id=0;
                jf[i].deadl=0;
                jf[i].profit=0;
               
                }
               
                sort(count);
                for(i=0;i<count;i++)
                {
                                k=getpos(j[i].deadl);
                                if(k!=-1)
                                jf[k]=j[i];
                                jfcount++;
                }
                printf("\nOrder of job sequence is : \n",i+1);
               
                for(i=0;i<jfcount-1;i++)
                {
                                printf("id:%d,deadline:%d,profit:%d\n",jf[i].id,jf[i].deadl,jf[i].profit);
                }
                getch();
return(0);

}

No comments:

Post a Comment