> Please help??? I am trying to solve a simple activity selection problem using greedy algorithm?

Please help??? I am trying to solve a simple activity selection problem using greedy algorithm?

Posted at: 2014-12-18 
include

using namespace std;

struct activity

{

int item,st,ft;

};

activity a[10]={ {1, 0, 6 }, {2, 1, 4}, {3, 2, 13}, {4, 3, 5}, {5, 3, 8},{6, 5, 7}, {7, 5, 9 },{8, 6, 10}, {9, 8, 11}, { 10,8,12} };

int main()

{

for(int i=0;i<10;i++)

{

int index=i;

for(int j=i;j<10;j++)

{

if(a[index].ft>a[j].ft)

{

index=j;

}

}

activity temp=a[index];

a[index]=a[i];

a[i]=temp;

}

/*for(int k=0;k<10;k++)

{

cout<
}*/

cout<<".................."<
cout<<"ITEM\tST\tFT"<


activity b[10];

b[0]=a[0];

int x=0;

int k=0;



for(int y=1;y<10;y++)

{

if(a[y].st>=a[x].ft)

{



b[y]=a[y];

k++;

x=y;



}

}

for(int l=0;l
{

cout<
}

}

the program should output

...........................

ITEM ST(starting time) FT(finishing time)

2 1 4

6 5 7

9 8 11

10 8 12

but it is outputting

2 1 4

garbage garbage garbage

press any.................

I can not figure out the problem.

please help me figuring the problem

THANKS IN ADVANCE