In this code , I am creating an array of structure and trying to sort the structure array based on "arr_time" field. I am having problem on how to pass the structure array by reference in function sort_process() .
#include<iostream>
using namespace std;
struct process {
public:
int p_id,arr_time,burst_time,comp_time;
};
void sort_process( process x[],int len)
{
int i,j;
process temp;
for(i=0;i<len;i++)
{
for(j=0;j<len-1;j++)
{
if(x[j].arr_time > x[j+1].arr_time)
{
temp = x[j];
x[j] = x[j+1];
x[j+1] = temp;
}
}
}
}
int main()
{
int n,i=0,j=0,k=0,t=0,flag;
cout<<"\n Enter number of processes : ";
cin>>n;
process p[n];
for(i=0;i<n;i++)
initialize(p[i]);
sort_process(p,n);
return 0;
}