File tree Expand file tree Collapse file tree
《数据结构与算法JavaScript描述》/习题/第三章 Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77 *
88 */
99
10+ //评注:该题出得有点语义不明,
11+ //对于数字字母混合的情况没有说明
12+ //故暂以都是字母或者数字为例
13+
14+
15+ /*
16+ * tools
17+ * a与b的大小比较,
18+ * 若a大于b则返回true
19+ */
20+ function compareSequence ( a , b ) {
21+
22+ //如果是字符串的数字( "11" < "2" )的处理
23+ var num1 = parseInt ( a , 10 ) ,
24+ num2 = parseInt ( b , 10 ) ;
25+ if ( typeof ( num1 ) === "number" && typeof ( num2 ) === "number" ) {
26+ if ( num1 > num2 ) {
27+ return true ;
28+ } else {
29+ return false ;
30+ }
31+ }
32+
33+ //字母的处理
34+ if ( a . toLowerCase ( ) > b . toLowerCase ( ) ) {
35+ return true ;
36+ } else {
37+ return false ;
38+ }
39+ }
40+
41+
42+ //注这里需配合课本中实现的List列表类来解答
43+ function insertBiggest ( element ) {
44+ for ( var i = 0 ; i < this . dataStore . length ; i ++ ) {
45+
46+ //需大于列表全部元素
47+ if ( ! compareSequence ( element , this . dataStore [ i ] ) ) {
48+ return false ;
49+ }
50+ }
51+
52+ this . append ( element ) ;
53+ return true ;
54+ }
You can’t perform that action at this time.
0 commit comments