## Selection Sort Algorithm Description

The Selection Sort algorithm finds the MINIMUM (Ascending Order) or MAXIMUM (Descending Order) element of the (sub)array and swaps it with the PIVOT or ("ANCHOR") element. The code for the algorithm is as follows:

### The Selection Sort Algorithm (Descending Order)

The following algorithm is based on the following principle:
1.Select the item with the maximum key
2.Exchange it with the first item data[0]
Then repeat these operation with the remaining n-1 items,
then with n-2 items, until only one item-the smallest-is left.
```        //data is an array of size n
for (pivot = 0; pivot < n-1; pivot++) {
max_index = pivot;
for (j = (pivot + 1); j < n; j++)
if (data[j] > data[max_index])
max_index = j;
swap(data[pivot], data[max_index]);
}//for
```

• ## Requirement Specifications

• User Model
1. A user should be able to see the west animation panel and the east code panel.
2. A user should be able to see the north title panel and the south control panel.
3. A user should be able to see the [Entire Shuffle] and [Next Swap] choice.
4. A user should be able to see the Execute, Stop, Restart, Help, Fun button on the control panel.
5. A user should be able to see the [SoundOn] and [SoundOff] choice.
6. A user should be able to see the online game manual as pop-up window after pressing the [Help] button.
7. After the two bars on the animation panel have been swaped, then a user should be able to see the small black square indicating that the swap finished.
8. When a user clicks on the Restart button or the Execute button and sound sets On, then a user should be able to listen to music.
9. When a user clicks on the Restart button or the Execute button and sound sets off, then a user should not be able to listen to music.
10. When a user clicks on the Restart button, a user should be able to see the
diffent number and color of bars on the animation panel.
11. When a user clicks a line in the code panel, a user should be able to see a explain box to match each code line.
12. When a user drags the mouse on the north title panel, a user should be able to listen to a frog sound.
13. When a user drags the mouse on the north title panel, a user should be able to the frog images at the mouse position.
14. When a user clicks on the Fun button sound sets on/off, then a user should not be able to listen to music/no music with frog image on the Animation Panel .

• ICS 665 Requirements
• WWW Environment
The Java and HTML languages are used.

• Various Media
Images, Audio, and Text are needed.
Utilities:
• PhotoShop for images
• CoolEdit for audio (Sound editor and convertor)
• Emacs for text

• Documentation
The goal, analysis, requirement specs, design, and code are described here.

• Relevancy: UH, ICS, ICS 665
This project is relevant to ICS 665 because the contents of the project focuce on algorithms used ICS 211.

• Non-commercial
The project will be non-commercial and there will be free downloads for non-commercial purposes if anyone so desires.

BarAnimation.java and VisualizeShuffle.java are used for the project with Dr. Stelovsky's permission. The images and sounds are not used for commercial papers.

• Objectives realized:
Understanding Selection Sort Algorithm concepts on the internet according to the above specifications:
There are a few buttons for a user. Whenever a user does the above, he or she can view images and listen to music or view the animation at the same time. These activities shows a user the concepts of Selection Sort Algorithm.

• ## Design

• Conceptual Design
```
Title Panel//display the selection sort title logo
|
|
====================
|                  |
Animation Panel           Code Panel
//sorting animation       //display algorithm in text
|                  |
|                  |
========= ==========
|
|
Control Panel//buttons and choice
(Execute                        -- Button
Entire Shuffle/Next Swap       -- Choice
Stop                           -- Button
Restart                        -- Button
Help                           -- Button
Fun                            -- Button
SoundOn/SoundOff               -- Choice)

```
• Functional Design
• User's Operations
• According to the applet manual, a user can perform the animation.
• The user's operations are as follows:
1. When a user selects one of the granularities, the animation style will be choosen (Entire Sort or Next Swap).
2. When a user selects the Execute button after granularity, the animation and code panels will be executed at the same time.
3. When a user selects the Soundon or off on the control panel, the sound style will be decided.
4. When a user presses the Restart button, then the animation panel will be rearranged for a user to restart.
5. When a user presses the Stop button, the current running thread will be stopped.
6. When a user clicks on the Help button, the applet manual is displayed as the pop-up window.
• Control Flow
• There are three main panels: AnimationPanel, CodePanel and ControlPanel.
First, the ControlPanel is for a user to handle the AnimationPanel and CodePanel.
Then, accoring to the ControlPanel, the AnimationPanel and CodePanel will be controlled.
• Data Flow
• As same as the above, the data flows from ControlPanel to AnimationPanel and CodePanel.

• Structual Design
• Main class: VisualizeSelectionSort ()
• Sub classes: AnimationPanel (), ControlPanel ()
• Convention in my program:
```        VisualizeSelectionSort ():Applet
init();
run();
action();
AppletDesign();
Finished();
Restart();
AllSoundStop();
|
Title (): North panel to show the title
mouseDrag();
paint();
|
Algorithm (): Thread for the animation
run();
SetGranularity();
Step();
Visualize();
____________|__________________________________________________________
|                      |                          |                    |
|                      |                          |                    |
AnimationCanvas()       CodePanel();             ExplainBox();      HelpWindow();
paint();               preferredSize();         SetText()           action();
Width();               paint ();                paint();
Height();              Reset ();                mouseExit();
GetX();                HighlightLine ();        SetText ();
GetY();                ColorLine ();
DrawBars();            mouseExit();
Fun();                 mouseUp();
```
• System Architecture
• Interfaces I: Execute Button, Entire Sort/Next Swap Choice, Help Button Restart Button, Stop Button, Fun Button, SoundOn/SoundOff Choice
Methods: handleEvent (), action (), mouseUp (), mouseDown (), mouseDrag () to activate the above buttons

• Screen Layouts
Four panels are displayed.
The north panel is the title panel and the south panel is the control panel.
The west panel is the animation panel and the east panel is the code panel.
```      ===========================
|       Title Panel       |
===========================
|            |            |
| Animation  |     Code   |
| Canvas     |     Panel  |
|            |            |
===========================
|     Control Panel       |
===========================
```
• Animation Panel
• Nine colorful bars will be shown as default.
When a user clicks on the Execute button on the Control Panel,
the bars will be moved and be swapped.
• Contol Panel
• Buttons -- Execute, Stop, Restart, Help, Fun
When a user clicks on one of the buttons, the animation will be executed.
• Execute button -- execute the sort animation
• Stop button -- stop the current thread
• Restart button -- refresh the panels to restart
• Help button -- show the manual with pop-up window
• Fun -- produces the sounds as a backgound with Fun animation
• Choice -- Entire Sort/Next Swap, On/Off
• Entire Sort/Next Swap -- decide the granularity of the bar animation
• SoundOn/SoundOff -- turns sound on or off

• Media Design