📄 page_1110.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>page_1110</title> <link rel="stylesheet" href="reset.css" type="text/css" media="all"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> </head> <body> <table summary="top nav" border="0" width="100%"> <tr> <td align="left" width="30%" style="background: #EEF3E2"><a style="color: blue; font-size: 120%; font-weight: bold; text-decoration: none; font-family: verdana;" href="page_1109.html">< previous page</a></td> <td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_1110</strong></td> <td align="right" width="30%" style="background: #EEF3E2"><a style="color: blue; font-size: 120%; font-weight: bold; text-decoration: none; font-family: verdana;" href="page_1111.html">next page ></a></td> </tr> <tr> <td align="left" colspan="3" style="background: #ffffff; padding: 20px;"> <table border="0" width="100%" cellpadding="0"><tr><td align="center"> <table border="0" cellpadding="2" cellspacing="0" width="100%"><tr><td align="left"></td> <td align="right"></td> </tr></table></td></tr><tr><td align="left"><p></p><table border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td align="right"><font face="Times New Roman, Times, Serif" size="2" color="#FF0000">Page 1110</font></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td> <td colspan="3" height="12"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Times New Roman, Times, Serif" size="3">When deleting from a data structure, the function can easily detect that the component is not there or that there is no component to remove. Should these functions have been written to guard against trying to delete a component that is not there? It depends on the interface between the calling code and the function. Either the caller is responsible for ensuring that the value is there to be deleted (guarantees the precondition), or the function should test for the case in which there is no value to delete or the specific value is not there. If the function does the testing, a flag should be returned to the caller showing whether or not the value was deleted successfully.</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td> <td colspan="3" height="12"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Times New Roman, Times, Serif" size="3">Following is a version of the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">DeleteTop</font><font face="Times New Roman, Times, Serif" size="3"> function in which error checking is included within the function itself. Notice that there is an additional parameter named </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">failed</font><font face="Times New Roman, Times, Serif" size="3">. Notice also that part of the original preconditionthat the list must not be emptyhas been eliminated.</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td> <td colspan="3" height="12"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">void聽OrdList::DeleteTop(<br />聽聽聽聽聽/*聽out聽*/聽ComponentType&聽item,聽聽聽聽聽聽//聽Item聽removed聽from聽list<br />聽聽聽聽聽/*聽out聽*/聽Boolean&聽聽聽聽聽聽聽failed聽)聽聽聽//聽Error聽flag<br /><br />//聽Precondition:<br />//聽聽聽聽聽component聽members聽of聽list聽nodes聽are聽in聽ascending聽order<br />//聽Postcondition:<br />//聽聽聽聽聽IF聽list聽at聽entry聽is聽empty<br />//聽聽聽聽聽聽聽聽聽failed聽==聽TRUE聽聽&&聽聽Value聽of聽item聽is聽undefined<br />//聽聽聽聽聽ELSE<br />//聽聽聽聽聽聽聽聽聽failed聽==聽FALSE<br />//聽聽聽聽聽聽&&聽item聽==聽component聽member聽of聽first聽list聽node聽at聽entry<br />//聽聽聽聽聽聽&&聽Node聽containing聽item聽is聽removed聽from聽linked聽list<br />//聽聽聽聽聽聽&&聽component聽members聽of聽list聽nodes聽are聽in聽ascending聽order<br /><br />{<br />聽聽聽聽if聽(head聽==聽NULL)<br />聽聽聽聽聽聽聽聽failed聽=聽TRUE;<br />聽聽聽聽else<br />聽聽聽聽{<br />聽聽聽聽聽聽聽聽NodePtr聽tempPtr聽=聽head;聽聽聽聽//聽Temporary聽pointer<br />聽聽聽聽聽聽聽聽item聽=聽head->component;<br />聽聽聽聽聽聽聽聽head聽=聽head->link;<br />聽聽聽聽聽聽聽聽delete聽tempPtr;<br />聽聽聽聽聽聽聽聽failed聽=聽FALSE;<br />聽聽聽聽}<br />}</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td> <td colspan="3" height="12"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Times New Roman, Times, Serif" size="3">Whenever it is possible for an error condition to occur in a function, you must decide where to check for the condition. If the caller is responsible for seeing that the situation does not occur, the assumption that the condition will not occur must be stated in the precondition of the function. If the function is to check for the error condition, your documentation of the function</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table></td></tr></table><p><font size="0"></font></p>聽 </td> </tr> <tr> <td align="left" width="30%" style="background: #EEF3E2"><a style="color: blue; font-size: 120%; font-weight: bold; text-decoration: none; font-family: verdana;" href="page_1109.html">< previous page</a></td> <td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_1110</strong></td> <td align="right" width="30%" style="background: #EEF3E2"><a style="color: blue; font-size: 120%; font-weight: bold; text-decoration: none; font-family: verdana;" href="page_1111.html">next page ></a></td> </tr> </table> </body> </html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -