codesys 瀹炵幇鍐掓场鎺掑簭-CODESYS璧勬簮涓嬭浇鍖-閰峰痉缃 - CoDeSys杞欢鏁欑▼涓嬭浇,CoDeSys宸ユ帶璧勮闂ㄦ埛
HSC6490-cn涓浗鍒堕狅紝涓浗鑺瘇
鏌ョ湅: 1388|鍥炲: 0

codesys 瀹炵幇鍐掓场鎺掑簭

[澶嶅埗閾炬帴]
  • TA鐨勬瘡鏃ュ績鎯
    鎱垫噿
    2017-11-9 20:49
  • 绛惧埌澶╂暟: 2 澶

    [LV.1]鍒濇潵涔嶅埌

    鍙戣〃浜 2023-4-12 23:25:05 | 鏄剧ず鍏ㄩ儴妤煎眰 |闃呰妯″紡
    浠涔堟槸鍐掓场鎺掑簭
    鍐掓场鎺掑簭鐨勮嫳鏂嘊ubble Sort锛屾槸涓绉嶆渶鍩虹鐨勪氦鎹㈡帓搴忋備箣鎵浠ュ彨鍋氬啋娉℃帓搴忥紝鍥犱负姣忎竴涓厓绱犻兘鍙互鍍忓皬姘旀场涓鏍凤紝鏍规嵁鑷韩澶у皬涓鐐逛竴鐐瑰悜鏁扮粍鐨勪竴渚хЩ鍔ㄣ
    鍐掓场鎺掑簭鐨勫師鐞嗭細
            姣忎竴瓒熷彧鑳界‘瀹氬皢涓涓暟褰掍綅銆傚嵆绗竴瓒熷彧鑳界‘瀹氬皢鏈綅涓婄殑鏁板綊浣嶏紝绗簩瓒熷彧鑳藉皢鍊掓暟绗 2 浣嶄笂鐨勬暟褰掍綅锛屼緷娆$被鎺ㄤ笅鍘汇傚鏋滄湁 n 涓暟杩涜鎺掑簭锛屽彧闇灏 n-1 涓暟褰掍綅锛屼篃灏辨槸瑕佽繘琛 n-1 瓒熸搷浣溿傝 鈥滄瘡涓瓒 鈥 閮介渶瑕佷粠绗竴浣嶅紑濮嬭繘琛岀浉閭荤殑涓や釜鏁扮殑姣旇緝锛屽皢杈冨ぇ鐨勬暟鏀惧悗闈紝姣旇緝瀹屾瘯涔嬪悗鍚戝悗鎸竴浣嶇户缁瘮杈冧笅闈袱涓浉閭荤殑涓や釜鏁板ぇ灏忓叧绯伙紝閲嶅姝ゆ楠わ紝鐩村埌鏈鍚庝竴涓繕娌″綊浣嶇殑鏁般
    鍏蜂綋鏄浣曠Щ鍔ㄧ殑鍛紵杩欓噷鍙傝冧簡(甯呭湴鐨勫啋娉℃帓搴)
    锛1锛夎捣濮嬫椂锛屽乏涓嬫爣鎸囧悜绗竴涓煶瀛愶紝鍙充笅鏍囨寚鍚戠浜屼釜鐭冲瓙锛岀劧鍚庢瘮杈
    codesys 瀹炵幇鍐掓场鎺掑簭-1.jpg


    锛2锛夌劧鍚庡乏鍙充笅鏍囧悓鏃跺悜鍙崇Щ鍔紝鍐嶆姣旇緝
    codesys 瀹炵幇鍐掓场鎺掑簭-2.jpg


    锛3锛夌涓瓒熺粨鏉熶箣鍚庯紝鏈澶х殑鐭冲瓙灏辩Щ鍔ㄥ埌浜嗘渶鍙宠竟
    codesys 瀹炵幇鍐掓场鎺掑簭-3.jpg


    锛4锛夋帴涓嬫潵灏变粠鍓╀笅 3 涓病鎺掑ソ搴忕殑鐭冲瓙涓户缁夊嚭鏈澶х殑锛岃鍒欏拰涓婇潰涓鏍
    codesys 瀹炵幇鍐掓场鎺掑簭-4.jpg


    锛5锛変笅闈㈢粰鍑鸿繖 4 涓煶瀛愬畬鏁寸殑婕旂ず杩囩▼
    codesys 瀹炵幇鍐掓场鎺掑簭-5.jpg


    璇濅笉澶氳锛屼笂甯︿唬鐮侊細
    棣栧厛灏辨槸瀹氫箟鍙橀噺锛
    1. PROGRAM PLC_PRG
    2. VAR
    3.         //鍐掓场鎺掑簭娉
    4.         xButton0                                          : BOOL ;         //鎺掑簭寮濮嬫寜閽
    5.         iBubbleSort1,iBubbleSort2         : INT ;                //鍐掓场寰幆鍙傛暟
    6.         iSort_n,iSortNum1,iSortNum2 : INT ;                //鎺掑簭杈呭姪鍙傛暟
    7.         arrDim1 : ARRAY[0..2,0..8] OF INT ;        //琛ㄦ牸鏁版嵁
    8. END_VAR
    澶嶅埗浠g爜
    浠ヤ笅灏辨槸鍐掓场鎺掑簭鐨勭▼搴忥細
    1. IF xButton0 THEN
    2.         FOR iSort_n := 0 TO 8 BY 1 DO
    3.                 arrDim1[1,iSort_n] := arrDim1[0,iSort_n] ;
    4.                 arrDim1[2,iSort_n] := arrDim1[0,iSort_n] ;
    5.         END_FOR
    6.         FOR iBubbleSort1 :=1 TO 8 BY 1 DO
    7.                 FOR iBubbleSort2 :=0 TO (8-iBubbleSort1) BY 1 DO
    8.                         IF arrDim1[1,iBubbleSort2] > arrDim1[1,iBubbleSort2+1] THEN //鍗囧簭鎺掑垪
    9.                                 iSortNum1 := arrDim1[1,iBubbleSort2];
    10.                                 arrDim1[1,iBubbleSort2] := arrDim1[1,iBubbleSort2+1];
    11.                                 arrDim1[1,iBubbleSort2+1] := iSortNum1;
    12.                         END_IF
    13.                         IF arrDim1[2,iBubbleSort2] < arrDim1[2,iBubbleSort2+1] THEN //闄嶅簭鎺掑垪
    14.                                 iSortNum1 := arrDim1[2,iBubbleSort2];
    15.                                 arrDim1[2,iBubbleSort2] := arrDim1[2,iBubbleSort2+1];
    16.                                 arrDim1[2,iBubbleSort2+1] := iSortNum1;
    17.                         END_IF
    18.                 END_FOR
    19.         END_FOR
    20.         xButton0 := 0;
    21. END_IF
    澶嶅埗浠g爜
    閫氳繃涓涓寜閽墽琛岀▼搴忥紝瀹炵幇鏁板瓧鐨勬帓搴忥紝鍒朵綔涓涓彲瑙嗗寲鏂囦欢锛岃繖鏍峰氨鍙互瀹炵幇浜嗭細
    codesys 瀹炵幇鍐掓场鎺掑簭-6.png


    鏉ユ墽琛屼互涓嬪惂锛岃鐪嬭繍琛屽悗鐨勬晥鏋滐細
    codesys 瀹炵幇鍐掓场鎺掑簭-7.png

    codesys 瀹炵幇鍐掓场鎺掑簭-8.png


    杩愯鍚庡疄鐜颁簡鏁板瓧鐨勫崌搴忓拰闄嶅簭鎺掑垪鈥斺斺斺
    鍚屾牱杩樻湁Python鐨勫啋娉℃帓搴忕殑绋嬪簭锛
    1. def bublle_sort(num):
    2.     for i in range(1,len(num)):
    3.         for n in range(0,len(num)-1):
    4.             if num[n] < num[n+1]:
    5.                 num[n],num[n+1] = num[n+1],num[n]      
    6.     return num
    7. if __name__ == "__main__":
    8.     num = [1,3,2,8,4,6]
    9.     print("闄嶅簭鎺掑垪涓猴細",bublle_sort(num))
    澶嶅埗浠g爜
    杩愯缁撴灉锛
    1. 闄嶅簭鎺掑垪涓猴細 [8, 6, 4, 3, 2, 1]
    澶嶅埗浠g爜
           鎬庝箞鏍凤紝鏄笉鏄劅瑙塩odesys涔熷彲浠ュ仛浜涗笉涓鏍风殑涓滆タ锛屽湪浠ュ悗鐨勬棩瀛愭垜浼氭寔缁拰澶у鍒嗕韩涓嶄竴鏍风殑codesys锛岃鎴戜滑宸ユ帶浜哄拰鍙互鐜╄浆浠g爜锛屼笅鏈熸垜鎵撶畻鐢╟odesys鍒朵綔绱姞鍣紒锛
    +10
    涓嶈禐涓涓紵
    鎵撹祻榧撳姳涓涓嬶紒
    鍥炲

    浣跨敤閬撳叿 涓炬姤

    鎮ㄩ渶瑕佺櫥褰曞悗鎵嶅彲浠ュ洖甯 鐧诲綍 | 绔嬪嵆娉ㄥ唽 鏂版氮寰崥鐧婚檰

    鏈増绉垎瑙勫垯

    椤堕儴qrcode搴曢儴
    鍏虫敞閰峰痉缃戣闃呭彿锛岃幏鍙栨洿澶氳祫璁紒

    QQ|灏忛粦灞|鎵嬫満鐗|Archiver|閰峰痉璁哄潧 ( 鑻廔CP澶16065247鍙-1 )|缃戠珯鍦板浘

    GMT+8, 2024-11-23 19:56 , Processed in 0.144912 second(s), 60 queries .

    閰峰痉缃

    © 2001-2013 Hicodesys. 鎶鏈敮鎸 by 閰峰痉缃

    蹇熷洖澶 杩斿洖椤堕儴 杩斿洖鍒楄〃