如何通过netlogo中的力量对海龟进行分类

时间:2017-02-19 09:22:15

标签: sorting netlogo

任何人都可以在netlogo帮助中实现冒泡排序,因为我想用他们的力量对海龟进行排序,而且我对这种语言知之甚少

turtles-own[strength]

to setup
ca
create-turtles num-turtle [
  set strength random 100
  fd 5
  set size 2
  set label strength
]
ask turtles [show sort [strength] of turtles ]

end

to bubblesort
  set liste [strength] of turtles
  if (turtle 0 [strength]) >= (turtle 1 [strength] ) ) [set size 5 ]
end

1 个答案:

答案 0 :(得分:0)

看看sort-on。它对我有用

turtles-own[strength]

to setup
ca
create-turtles num-turtle [
  set strength random 100
  fd 5
  set size 2
  set label strength
]
show sort-on [strength] turtles

end

控制台中的结果是一个列表

observer: [(turtle 1) (turtle 2) (turtle 7) (turtle 8) (turtle 5) (turtle 0) (turtle 6) (turtle 3) (turtle 9) (turtle 4)]