473,401 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Banker's Algorithm

c++
I wrote this code that should tell to the user who are the best
processes to release a unit of a resource using the banker's algorithm

#include<iostream>
#include<conio>
#include<stdio>
#include<stdlib>
void main()
{

const int max = 10; //max multiplicity
int i, j, z; //counters
int P, L, N; //P=
processes, L= FREE, N= maximum multiplity
int A[max], R[max], M[max]; //A= allocates, R=
request, M= maximum requests
int RS[max]; //RS= folowing request
int LS[max]; //free resurces after the i-
allocation
int CP[max]={0}; //CP= processes classification
int MAX[max];
int lim; //max limit

do
{
cout<<"\HOW MANY PROCESSES DO YOU WANT? ";
cin>>P;
}while(P>max);

cout<<"\nINSERT THE MULTEPLICITY OF THE RESOURCE: ";
cin>>N;

for(i=0;i<P;i++)
{
cout<<"\nHOW MANY UNIT HAS THE P"<<i<<" PROCESS? ";
cin>>A[i];
cout<<"\nHOW MANY UNIT REQUEST THE P"<<i<<" PROCESS? ";
cin>>R[i];
cout<<"\nWHAT IS THE MAX NUMBER OF UNITS OF THE P"<<i<<"
PROCESS? ";
cin>>M[i];
cout<<"\n\n";
}

L=N;
for(i=0; i<P; i++)
L-=A[i]; //nuber of units still idle

for(i=0; i<P; i++)
{
if(R[i]<=L) //is secure?
{
RS[i]=M[i]-A[i]-R[i]; //next request
LS[i]=L-R[i]; //idle resuorces after the allocation

}
else //isn't secure
{
LS[i]=-1;
}
}
for(i=0; i<P; i++)
MAX[i]=-1; //or 0???

z=0;
for(i=0; i<P; i++)
{
if(i==0)
{
for(j=0; j<P; j++)
{
if(LS[j]>=MAX[z])
{
MAX[z]=LS[j];
CP[z]=j;

lim=MAX[z];
}
}
}
else
{
for(j=0; j<P; j++)
{
if((LS[j]>=MAX[z])&&(LS[j]<lim))
{
MAX[z]=LS[j];
CP[z]=j;

lim=MAX[z];
}
}
}

z++;
}

for(i=0; i<P; i++)
{
if(LS[i]!=-1)
cout<<"\nTHE PROCESS NUMBER "<<i<<" IS THE "<<CP[i]<<"st
CHOICE\n";
else
cout<<"THE PROCESS NUMBER "<<i<<" IS NOT SECURE";
}
getch();
}

------------------

The program doesn't do what it shuld do: it doesn't putthe processes in
the right order.

I don't know how to wirte the piece of code that tell to the user that
the best choise is the precess that has the bigger value of LS[]

Could anyone tell me what I should write?

--
Questa č una firma automatica di MesNews.
Sito: http://www.mesnews.net

Jul 22 '05 #1
0 4675

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Jack Smith | last post by:
Hello, any help appreciated with following problem. I figured out the algorithm (I think), just having trouble proving it is optimal. Suppose we are given n tasks each of which takes 1 unit...
10
by: bpontius | last post by:
The GES Algorithm A Surprisingly Simple Algorithm for Parallel Pattern Matching "Partially because the best algorithms presented in the literature are difficult to understand and to implement,...
32
by: Cmorriskuerten | last post by:
HI, is this is this solution to test if a number is a prime number or not: /* * Is n a prime number? * Return TRUE (1): n is a prime number * Return FALSE (0): n is a *not* a prime number...
113
by: Bonj | last post by:
I was in need of an encryption algorithm to the following requirements: 1) Must be capable of encrypting strings to a byte array, and decyrpting back again to the same string 2) Must have the same...
4
by: FBM | last post by:
Hi, I am working on a program that simulates one of the elements of ATM. The simulation stores events which occurs every some milliseconds for a certain amount of time. Every time that an event...
2
by: Julio C. Hernandez Castro | last post by:
Dear all, We have just developped a new block cipher called Raiden, following a Feistel Network structure by means of genetic programming. Our intention now consists on getting as much feedback...
1
by: Peniel | last post by:
Please If any one of you know how to write code which will test the safe sequency i.e code that express Banker's algorithm The pseudocode is as folows  Step1: Let Work and Finish be vectors of...
0
by: aruna | last post by:
hey guys i earlier had very valuable responses from you all for base64 encoding algorithm.so thank for that. so now i need your assistance to do a float encoding algorithm. you may wonder why i'm...
1
by: almurph | last post by:
Hi everyone, Concerning the Needleman-Wunsch algorithm (cf. http://en.wikipedia.org/wiki/Needleman-Wunsch_algorithm) I have noticed a possible loop. Inside the algorithm there is an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.