辅导Ball Sorting、讲解Python, C/C++、辅导BallSet留学生

- 首页 >> Python编程

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.


站长地图