Skip to content

Instantly share code, notes, and snippets.

@NithishKolli
Last active January 2, 2016 16:39
Show Gist options
  • Save NithishKolli/8331947 to your computer and use it in GitHub Desktop.
Save NithishKolli/8331947 to your computer and use it in GitHub Desktop.
#include<iostream>
using namespace std;
class Banker
{
private:
public:
int maxResources,stock;
};
bool Banker::allocationAlgorithm(Customer customers[],int nCustomers)
{
bool flag,flag1;
int sortedIndexes[nCustomers];
int currentIndex=nCustomers;
while(checkSafeState(customers[],nCustomers))
{
sortedIndexes=sortArray(customers[],nCustomers);
}
}
int[] sortArray(Customer customers[],int nCustomers)
bool Banker::checkSafeState(Customer customers[],int nCustomers)
{
bool flag=false;
for(int i=0;i<nCustomers;i++)
{
if(customer[i].request<stock){
flag=true;
}
}
return flag;
}
class Customer
{
public:
int maxNeed,allocated,request;
bool fulfilled=false;
};
int main()
{
int maxRes,nCustomers,tResources,choice;
bool flag;
Customer *customers;
cout<<"Enter the Types of Resources"<<endl;
cin>>tResources
cout<<"Enter the maximum resources of the banker";
cin>>maxRes;
cout<<"Enter the number of Customers";
cin>>nCustomers;
customers = new customer[nCustomers];
cout<<"Enter the maximum needs of each customer"<endl;
for(int i=0;i<nCustomers;i++)
{
cout<<"Maximum need of customer "<<i;
cin>>customer[i].maxNeed;
}
do{
cout<<"What do you want to do?"<<endl<<"1.Check for safe state after a allocation"<<endl<<"2.Simulate a set of possible allocations"
cin>>choice;
if(choice==1)
{
checkSafeState(customers[],nCustomers);
flag=false;
}
else if(choice==2)
{
allocationAlgorithm(customers[],nCustomers);
flag=false;
}
else
{
cout<<"Enter either 1 or 2"
flag=true;
}
}
while(flag)
/*
for(int i=0;i<nCustomers;i++)
{
cin>>customer[i].maxNeed;
}*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment