三焦不通吃什么中成药| 心肌缺血吃什么食物好| 孙权孙策什么关系| 喝什么可以减肥| 月经周期变短是什么原因| 花重锦官城的重是什么意思| 金与什么相生相克| 手指是什么生肖| 投射效应是什么意思| 风湿类风湿有什么区别| 肠胃功能紊乱什么症状| 一线天是什么意思| 天门冬氨酸氨基转移酶是什么| 供给侧改革什么意思| 羊属于什么科| 月经2个月没来是什么原因| 苦瓜吃多了有什么坏处| 阿司匹林什么时候吃| 牙齿冷热都疼是什么原因| 心梗是什么原因引起的| 酸奶可以做什么美食| 夜晚尿频尿多是什么原因| 什么时候测试怀孕最准确的| 为什么我不快乐| 用盐洗头发有什么好处| 舌尖发麻是什么原因引起的| 子不孝父之过下一句是什么| 7.21是什么日子| 结节钙化是什么意思| 稽留流产是什么意思| 儿童受凉咳嗽吃什么药| 肚子疼吃什么药管用| 灯火通明是什么生肖| 公价是什么意思| 水钠潴留什么意思| 什么发色显皮肤白| 起什么转什么成语| 神经外科和神经内科有什么区别| 银杏叶片有什么作用| 头疼需要做什么检查| 牵牛花是什么颜色的| 1994年是什么命| 生吃黄瓜有什么好处| 为什么男人吃石榴壮阳| 猪笼入水是什么意思| 畅销是什么意思| 谷草谷丙低是什么原因| 舌系带挂什么科| 化学学什么| dha什么时候吃效果最好| 食管鳞状上皮增生是什么意思| 纹身的人是什么心理| 人为什么要日b| 孕早期需要注意什么| 太阳指什么生肖| 丹参片和复方丹参片有什么区别| 瘦西湖为什么叫瘦西湖| 处女膜什么样子| 抄手是什么| 哈喇味是什么味道| 芦笋炒什么好吃| 养胃吃什么水果| qeelin是什么牌子| 走投无路是什么意思| 额头和下巴长痘痘是什么原因| 辗转是什么意思| abby是什么意思| 江西有什么景点| 谷草谷丙低是什么原因| 查心脏挂什么科| 百田森的鞋什么档次| 产后抑郁症有什么表现症状| 口腔医学专业学什么| bb霜和cc霜有什么区别| 多酚是什么| 身体水肿是什么原因引起的| 金益什么字| 加盟什么店最赚钱投资小| 蛋白粉什么时间喝最好| 2岁属什么生肖| 吃什么对脑血管好| 什么官许愿| 餐标是什么意思| 枕头底下放剪刀有什么说法| pp材质和ppsu材质有什么区别| 甲亢和甲状腺有什么区别| 邯郸学步的寓意是什么| 参乌健脑胶囊适合什么人吃| 什么叫散光| 小腿肿是什么原因| 血象是指什么| 79年属什么的生肖| 身体不适是什么意思| 药物制剂是干什么的| 五月十三号是什么日子| 碱面是什么| 夏天喝什么解渴| 体癣用什么药| 蜜饯是什么| 大便不正常是什么原因造成的| 五六天不拉大便是什么原因| 谈婚论嫁什么意思| 什么地问填词语| 明前茶什么意思| sun代表什么| 天地不仁以万物为刍狗什么意思| 大学211和985是什么意思| 氢化聚异丁烯是什么| 逆商是什么意思| 静脉曲张是什么症状| 你喜欢我什么我改| 恶心想吐肚子疼是什么原因| 阴山是今天的什么地方| 脸部过敏红痒抹什么药| 老是干咳什么原因| 双子座和什么座最配| ipmn是什么意思| 水杨酸有什么作用| 老鼠属于什么类动物| 小龙虾不能和什么一起吃| 肚子胀恶心想吐是什么原因| pangchi是什么牌子的手表| 球蛋白有什么作用和功效| 酸萝卜别吃什么意思| 优对什么| 什么叫自私的人| 男人吃什么补肾| 什么时间段买机票最便宜| 浅表性胃炎伴糜烂吃什么药效果好| 月经前几天是什么期| 甲状腺球蛋白低说明什么| 25是什么生肖| 猫代表什么数字| 芝士是什么材料做的| 梦见煮饺子是什么意思| 主动脉硬化什么意思| 来例假肚子疼吃什么药| 胸推是什么| 指鹿为马是什么意思| 女人吃牛油果有什么好处| 盆腔磁共振平扫能查出什么| 勃起不硬吃什么药| 什么叫ins风格| 喝什么利尿| 早搏是什么意思| 属鸡的幸运色是什么颜色| 梦见很多牛是什么兆头| 旁支是什么意思| 毒龙钻什么意思| 太平间是什么意思| 女人右下巴有痣代表什么| 腰腿疼痛吃什么药效果好| 甲亢病是什么原因引起的| 规格型号是什么意思| 囗腔溃疡吃什么维生素| 荨麻疹不能吃什么| 心系是什么意思| 腮腺炎用什么药| 射手男和什么座最配对| gr是什么意思| 省管干部是什么级别| 雌蕊由什么组成| 什么什么不舍| 10月9日什么星座| 清欢渡是什么意思| 老人流口水是什么原因| 帕金森病是什么病| 看肠胃挂什么科室| 月经黑色是什么原因| 眼睛发蓝是什么原因| 肠胃炎不能吃什么| 做梦梦到小孩子是什么意思| 为什么喝中药越来越胖| 梦见好多南瓜是什么意思| 热淋是什么病| 寻的部首是什么| 叶字五行属什么| 择日什么意思| 处女座属于什么星象| 冠脉壁钙化是什么意思| 洋葱为什么会让人流泪| 官星是什么意思| 夏侯霸为什么投降蜀国| 隔空打牛是什么意思| 新型冠状病毒有什么症状| 糖原是什么| 小便无力是什么原因| 澳大利亚有什么动物| 皮蛋不能和什么一起吃| 山药和什么搭配最好| 足字旁的字和什么有关| 璠字取名寓意什么| 低血压高是什么原因造成的| 妊娠是什么| 刀子是什么意思| 四川大学校长什么级别| 双鱼座是什么象星座| 喝菊花茶有什么功效| 种植牙为什么那么贵| 菊花茶适合什么人喝| 什么是乳胶床垫| 什么是重心| 什么是股癣| 绿豆什么人不能吃| rush是什么东西| 鸽子喜欢吃什么食物| 内分泌紊乱吃什么药| 牙齿是什么材质| 湿疹擦什么药好| 婕妤是什么意思| 小恙是什么意思| 扦插是什么意思| nec投影仪是什么牌子| yg是什么意思| 友谊是什么意思| 痛经什么原因| 掉头发缺什么| 纯净水和矿泉水有什么区别| 甲状腺1类是什么意思| 淋巴结在什么位置| 骨龄大于年龄意味着什么| 什么车可以闯红灯| 早泄是什么原因| 尿酸高喝什么水最好| 岱字五行属什么| 肝病不能吃什么| 后背凉凉的是什么原因| 胆汁酸高是什么原因| 痔疮便血吃什么药| cpa是什么证书| 女性夜尿多吃什么调理| 经期适合喝什么汤| 全身检查要挂什么科| 氯雷他定片主治什么病| 山川是什么意思| 肚脐右边是什么器官| 翡翠都有什么颜色| 睡觉被口水呛醒是什么原因| 前列腺增生是什么原因引起的| 科学家是干什么的| 摸底是什么意思| 家里出现蟑螂预示什么| 患得患失什么意思| 什么意| 臭鼬是什么动物| 尿酸高肌酐高是什么原因呢| 左什么结构| 永无止境是什么意思| 三个大是什么字| 老人脚背肿是什么原因| 翠绿色配什么颜色好看| 孕妇感冒可以吃什么药| 亲子鉴定挂什么科| 跌宕起伏什么意思| 白羊座男和什么星座最配| 抄手是什么食物| 怕热易出汗是什么原因| 灵芝什么人不能吃| 生动是什么意思| 雪花鱼是什么鱼| 省委书记什么级别| 胃功能四项检查是什么| 人得猫癣用什么药| 截石位是什么意思| 百度Jump to content

拥抱监管合规发展 易通贷荣膺“中国金融科技先锋企业

From Wikipedia, the free encyclopedia
百度 更重要的是,这几款车基本上10万块都能搞定!当然,如果没有炫酷动感的造型和内饰,估计也入不了我这朋友的眼。

In computer programming, a sentinel value (also referred to as a flag value, trip value, rogue value, signal value, or dummy data) is a special value in the context of an algorithm which uses its presence as a condition of termination, typically in a loop or recursive algorithm.

The sentinel value is a form of in-band data that makes it possible to detect the end of the data when no out-of-band data (such as an explicit size indication) is provided. The value should be selected in such a way that it is guaranteed to be distinct from all legal data values since otherwise, the presence of such values would prematurely signal the end of the data (the semipredicate problem). A sentinel value is sometimes known as an "Elephant in Cairo", due to a joke where this is used as a physical sentinel. In safe languages, most sentinel values could be replaced with option types, which enforce explicit handling of the exceptional case.

Examples

[edit]

Some examples of common sentinel values and their uses:

Variants

[edit]

A related practice, used in slightly different circumstances, is to place some specific value at the end of the data, in order to avoid the need for an explicit test for termination in some processing loop, because the value will trigger termination by the tests already present for other reasons. Unlike the above uses, this is not how the data is naturally stored or processed, but is instead an optimization, compared to the straightforward algorithm that checks for termination. This is typically used in searching.[1][2]

For instance, when searching for a particular value in an unsorted list, every element will be compared against this value, with the loop terminating when equality is found; however, to deal with the case that the value should be absent, one must also test after each step for having completed the search unsuccessfully. By appending the value searched for to the end of the list, an unsuccessful search is no longer possible, and no explicit termination test is required in the inner loop. After the search, one must decide whether a true match was found, but this test needs to be performed only once rather than at each iteration.[3] Knuth calls the value so placed at the end of the data, a dummy value rather than a sentinel.

Examples

[edit]

Array

[edit]

For example, if searching for a value in an array in C, a straightforward implementation is as follows; note the use of a negative number (invalid index) to solve the semipredicate problem of returning "no result":

int find(int arr[], size_t len, int val)
{
    for (int i = 0; i < len; i++)
        if (arr[i] == val)
            return i;
    return -1; // not found
}

However, this does two tests at each iteration of the loop: whether the value has been found and whether the end of the array has been reached. This latter test is what is avoided by using a sentinel value. Assuming the array can be extended by one element (without memory allocation or cleanup; this is more realistic for a linked list, as below), this can be rewritten as:

int find(int arr[], size_t len, int val)
{
    int i;

    arr[len] = val; // add sentinel value
    for (i = 0;; i++)
        if (arr[i] == val)
            break;
    if (i < len)
            return i;
    else
            return -1; // not found
}

The test for i < len is still present, but it has been moved outside the loop, which now contains only a single test (for the value), and is guaranteed to terminate due to the sentinel value. There is a single check on termination if the sentinel value has been hit, which replaces a test for each iteration.

It is also possible to temporarily replace the last element of the array by a sentinel and handle it, especially if it is reached:

int find(int arr[], size_t len, int val)
{
    int last;

    if (len == 0)
        return -1;
    last = arr[len - 1];
    arr[len - 1] = val; // add sentinel value

    int i;
    for (i = 0;; i++)
        if (arr[i] == val)
            break;
    arr[len - 1] = last;
    if (arr[i] == val)
            return i;
    else
            return -1; // not found
}

See also

[edit]

References

[edit]
  1. ^ Mehlhorn, Kurt; Sanders, Peter (2008). "3. Representing Sequences by Arrays and Linked Lists" (PDF). Algorithms and Data Structures: The Basic Toolbox. Springer. p. 63. ISBN 978-3-540-77977-3.
  2. ^ McConnell, Steve (2004). Code Complete (2nd ed.). Redmond: Microsoft Press. p. 621. ISBN 0-7356-1967-0.
  3. ^ Knuth, Donald (1973). Sorting and searching. The Art of Computer Programming. Vol. 3. Addison-Wesley. p. 395. ISBN 0-201-03803-X.
but什么意思 鼠分念什么 什么油炒菜好吃又健康 塔罗牌逆位是什么意思 宝宝吐奶是什么原因
晨勃是什么 血压低什么症状 骨折后吃什么好 兵解是什么意思 胆囊炎输液用什么药
嗓子疼吃什么药效果最好 砍单是什么意思 黄眉大王是什么妖怪 大败毒胶囊主治什么病 火花塞坏了有什么症状
阴液是什么 有什么有什么的四字词语 wt是什么意思 上不下要读什么 长期便秘吃什么药效果最好
梦见和女儿吵架是什么意思zsyouku.com 怀孕肚子疼是什么原因hcv7jop9ns6r.cn 私定终身是什么意思hcv8jop1ns9r.cn 奶茶色是什么颜色hcv8jop8ns3r.cn 潘多拉属于什么档次hcv9jop2ns9r.cn
98年属虎的是什么命hcv8jop5ns3r.cn 水潴留是什么意思hcv9jop4ns8r.cn 腋臭看什么科hcv8jop6ns0r.cn 抖m是什么意思hcv9jop3ns2r.cn 天荒地老是什么生肖hcv8jop1ns3r.cn
室上速是什么原因导致的hcv8jop2ns3r.cn 挑拨离间是什么意思hcv7jop5ns3r.cn 健脾祛湿吃什么中成药hcv9jop1ns8r.cn 日值四离是什么意思hcv7jop6ns7r.cn 感冒发烧吃什么好hcv8jop2ns2r.cn
阴灵是什么意思hcv7jop7ns1r.cn 口加一笔变成什么字hcv9jop2ns7r.cn 门的单位是什么hcv8jop0ns6r.cn 眼睛发黄是什么原因hcv8jop0ns8r.cn 水土不服吃什么药hcv9jop7ns5r.cn
百度