home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
listings
/
v_09_12
/
9n12032a
< prev
next >
Wrap
Text File
|
1991-10-15
|
2KB
|
57 lines
---------------------------------------------------
FUNCTION LOCATE_NODE: The steps to locating a node in the list are:
A. Make one cycle of the list starting at the root. Since process idle
has priority zero and the user cannot add nodes with a priority less
than 1, the idle node is always the last one in the cycle.
B. If the priority we are searching for is equal to the current
entry's, return the previous entry's address.
C. Else if the new priority is greater than that in the list the one we
are searching for isn't in the list. So is we were looking for
an exact match indicate it wasn't found. For an inexact match
return the address of the previous node (which must be greater than
the one we are searching for).
D. The match may still be coming so keep looking.
E. We've reached the end of the list so is we were looking for
an exact match indicate it wasn't found. For an inexact match
return the address of the previous node (which must be greater than
the one we are searching for).
-------------------------------------------------------------- */
Node *locate_node(unsigned priority, int match)
{
const Node *pnode = proot_node;
/*A*/ while (pnode->process != idle) {
/*B*/ if (priority == pnode->priority) {
return pnode->pbwd;
}
/*C*/ else if (priority > pnode->priority) {
if (match == EXACT) {
return NULL;
}
else {
return pnode->pbwd;
}
}
/*D*/ else {
pnode = pnode->pfwd;
}
}
/*E*/ if (match == EXACT) {
return NULL;
}
else {
return pnode->pbwd;
}
}