联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp

您当前位置:首页 >> Python编程Python编程

日期:2018-12-02 10:33

Simple Ball Sorting

For this project, you will implement the basic steps of Insertion Sort and Selection Sort.

As the algorithm we discussed in the class, you need to write three member functions

inside the “BallSet” class to sort the randomly generated balls and display each step of

the temporary sorting result in the 3D scene.

The example above shows the steps of applying “insertion sort” to sort the balls step by

step. Each row represents one step of the temporary sorting result. The top row is the

initially generated balls in random order; the last row is the fully sorted balls. For this

sorting task, we use the ball’s size or color brightness as the reference to sort them in

such a way that their corresponding sizes are arranged in an increasing order or their

corresponding color brightness are arranged in an increasing order. To accomplish this

task, there are three important functions you need to finish:

Three Functions to Implement:

(1) showBalls(self, z) (30%)

This function is used to draw the current balls during sorting in one row. The

parameter “z” will determine this row’s corresponding level in the z direction, i.e.

the first row’s z can be set to 0 or a small number; as the sorting progresses, the

row’s z value should increase. You can set the increase step or the z growth

speed to an appropriate value, as long as any two neighbor rows do now overlap.

This “showBalls(self, z)” function should be called or triggered by the

“selectionSort(self)” function or “insertionSort(self)” function during each iteration

of the sorting process.

(2) selectionSort(self) (35%)

In this function you should use the selection sort algorithm we talked about in the

class. You actually need to sort the balls array member of the “BallSet” class, i.e.

“self.bass[]”. You will use a loop to iteratively re-arrange the array step by step.

At the end of each iteration, it calls the “showBalls(self, z)” function to display the

current partially sorted balls in the 3D scene. So after “selectionSort(self)” is

executed, an array of balls are shown in the 3D scene with each row

representing the output from each iteration.

(3) insertionSort(self) (35%)

This function has the same role as “selectionSort(self)” function but uses

insertion sort algorithm to sort the balls. Similarly, for each step or at the end of

each iteration, , it calls the “showBalls(self, z)” function to display the current

partially sorted balls in the 3D scene.


版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp