回复:935888712@qq.com

TonyWang

  • 帖子

    2
  • 精华

    0
  • 被关注

    0

论坛等级:新手

注册时间:2022-07-07

普通 普通 如何晋级?

发布于 2022-12-16 21:35:12

3楼

/双向链表

//起始:.Prev = -1

//尾端:.Next = -1

//单链表无法设置首部标志

//单链表如果存储上前面的被删,后又补上,无法判断首部

//*********************************************************

REGION 如果 "RecipeName" 为空,退出

    IF LEN(IN := #recipeName) = 0 THEN

        #errorCode := 16#9001;              //未输入配方名

        #done := FALSE;

        #error := TRUE;

        #recipeIndexFound := -1;

        RETURN;

    END_IF;

END_REGION


REGION 输入数组上限

    #tempUpper := #upperBound;

END_REGION

REGION 找第一条非空有效记录

    FOR #temp_i := 0 TO #tempUpper DO

        //链表指针不同,则为有效记录

        IF #recipeList.RecipeList[#temp_i].Prev <> #recipeList.RecipeList[#temp_i].Next THEN

            #tempFirstLog := #temp_i;

            EXIT; 

在这里不是查找到的是首记录而且是非空的吗?

        END_IF;

        //最后一条记录仍无效

        IF #temp_i = #tempUpper THEN

            #errorCode := 16#9002;              //链表为空,无有效记录

            #done := FALSE;

            #recipeIndexFound := -1;

            RETURN;

        END_IF;

    END_FOR;

END_REGION

REGION 正序查配方

    #temp_i := #tempFirstLog;     //从第一条记录开始

    #tempIndexFound := -3;   // >= 0为找到的记录索引

    WHILE #temp_i >= 0 DO

        IF #recipeName = #recipeList.RecipeList[#temp_i].ProductName THEN

            #tempIndexFound := #temp_i;

            EXIT;

        END_IF;

        IF #recipeList.RecipeList[#temp_i].Next = -1 THEN

            //正向无结果

            // Next = -1 为结束标志

            #tempIndexFound := -1;

            //退出循环

            EXIT;

        END_IF;

        //链表指针指向下一条记录

        #temp_i := #recipeList.RecipeList[#temp_i].Next;

    END_WHILE;

END_REGION

REGION 反向查找

    IF #tempIndexFound < 0 THEN

        #temp_i := #recipeList.RecipeList[#tempFirstLog].Prev;

这个地方不太理解,反向查找不得从数组后边来吗,为这么从第一个开始,上来temp _i=-1吗后面无法进行了。

        WHILE #temp_i >= 0 DO

            IF #recipeName = #recipeList.RecipeList[#temp_i].ProductName THEN

                #tempIndexFound := #temp_i;

                EXIT;

            END_IF;

            IF #recipeList.RecipeList[#temp_i].Prev = -1 THEN

                //反向查找无结果

                // Prev = -1 为起始标志

                #tempIndexFound := -7;

                EXIT;

            END_IF;

            //查链表下一条记录

            #temp_i := #recipeList.RecipeList[#temp_i].Prev;

        END_WHILE;

    END_IF;

END_REGION

REGION 输出

    IF #tempIndexFound >= 0 THEN

        //根据配方名称找了到配方

       //如果需要输出找到的完整记录,添加输入参数: Recipe_Found 类型REF_TO "typeBeerRecipe_Link_x1"

       //#Recipe_Found^ := #recipeList.RecipeList[#tempIndexFound];

        #done := True;              //输出状态

        #error := FALSE;

        #errorCode := 0;

        #recipeIndexFound := #tempIndexFound;

        RETURN;     //结束查找

    END_IF;

    

    #done := FALSE;                 //未找到配方

    #error := TRUE;

    #errorCode := 16#9003;

    #recipeIndexFound := -1;

END_REGION


评论
编辑推荐: 关闭

请填写推广理由:

本版热门话题

PLC编程精英训练营

共有1548条技术帖

相关推荐

热门标签

相关帖子推荐

guzhang

恭喜,你发布的帖子

评为精华帖!

快扫描右侧二维码晒一晒吧!

再发帖或跟帖交流2条,就能晋升VIP啦!开启更多专属权限!

  • 分享

  • 只看
    楼主

top
X 图片
您收到0封站内信:
×
×
信息提示
很抱歉!您所访问的页面不存在,或网址发生了变化,请稍后再试。