Table-Driven Methods

博客介绍了表驱动方法在P2中的应用及表中条目的查找方式。包括直接访问,如用数组存每月天数并以月份为索引;索引访问,用主数据查索引表键值再查主数据;阶梯访问,表条目适用于数据范围,可通过循环检查得分确定等级,还给出相关注意建议。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

First, an example of table-driven method in P2

How to look up entries in the table
1. Direct Access
For example, you want to the days number for every month, store the days in an array and use month as the index.
2. Indexed Access
When you use indexes, you use the primary data to look up a key in an index table and then you use the value from the index table to look up the main data you're interested in.
3. Stair-Step Access
The general idea of stair-step structure is that entries in a table are valid for ranges of data rather than for distinct data points.
The stair-step approach categorizes each entry by determining the level at which it hits a "staircase".
To use the stair-step method, you put the upper end of each range into a table and then write a loop to check a score against the upper end of each range. When you find the point at which the score first exceeds the top of a range, you know what the grade is.
      Watch the endpoints.
      Consider using a binary search rather than a sequential search.
      Consider using indexed access instead of the stair-step technique.
      Put the stair-step table lookup into its own routine.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值