Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 18321d6

Browse files
debug start button & performace improvments
2 parents 305a7bc + 0cc9f22 commit 18321d6

File tree

4 files changed

+69
-11
lines changed

4 files changed

+69
-11
lines changed

‎README.md‎

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,34 @@
1-
## Selective Sorting Algorithm
2-
Selection sort is a simple sorting algorithm. This sorting algorithm is a comparison-based algorithm in which the list is divided into two parts:
3-
the sorted part at the left end and the unsorted part at the right end.
4-
Initially, the sorted part is empty and the unsorted part is the whole list, in this code, each part is considered as an array.
1+
## What is an Algorithm?
2+
An algorithm is a set of instructions or rules that guide the computer or software in performing a particular task or solving a problem 1.
3+
4+
## What is Selection Sorting Algorithm and How Does it Help Us?
5+
Selection sort is an in-place comparison-based algorithm that divides the list into two parts, the sorted part on the left and the unsorted part on the right . It works by repeatedly selecting the smallest (or largest) element from the unsorted portion of the list and moving it to the sorted portion of the list .
6+
7+
Selection sort has several advantages over other sorting algorithms. It is simple to understand and implement, requires no additional memory space, and performs well on small lists . However, it is not suitable for large lists as its time complexity is O(n2) .
8+
9+
10+
## Preview
11+
go to this link and see the preview of this project online
12+
13+
https://selection-sorting-algorithm.vercel.app
14+
15+
## Installation
16+
To install this project, simply clone the repository and open the index.html file in your web browser.
17+
```bash
18+
git clone https://github.com/amirallami-code/selection-sorting-algorithm
19+
```
20+
21+
## License
22+
This project does not have any license.
23+
24+
## Usage
25+
To use this project and see how it works to sort our numbers, we should type a number in the input field that reads `Enter your number` and click on the `Add Number` button to add our number to the basket of numbers that are not sorted (`your numbers` section). When you have typed all of your numbers and added them to the basket, click on the `Start Sorting` button. The result will appear in the `After Sorting` section, where you can see that your numbers are sorted!
26+
27+
## References
28+
- https://www.geeksforgeeks.org/selection-sort/
29+
- https://www.simplilearn.com/tutorials/data-structure-tutorial/selection-sort-algorithm
30+
31+
## Contact Information
32+
If you have any questions or concerns about this project, please contact us at amirallami.dev@gmail.com
33+
34+
I hope this helps! Let me know if you have any other questions.

‎index.html‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,27 @@
1111
<div class="text-div">
1212
<h2>Selective Sorting</h2>
1313
<p>Sort a list of numbers</p>
14+
<<<<<<< HEAD
1415
<p>
1516
write your number, add it to the list of unsorted entries <br />
1617
and click on the "Start sorting" button!
18+
=======
19+
<p class="description">
20+
HOW TO START: write your number, push it to the basket below,<br />
21+
and click the "start sorting" button to start(or press enter)!
22+
>>>>>>> 0cc9f2281468d906974b94204367c2cebec1de7f
1723
</p>
1824
<div>
1925
<input type="number" placeholder="Enter your number" id="input" />
2026
<button type="button" id="button1">add number</button>
2127
<div>
28+
<<<<<<< HEAD
2229
<button type="button" id="button2" disabled>start sorting</button>
2330
<p id="error">enter the correct value!</p>
31+
=======
32+
<button type="button" id="button2">start sorting</button>
33+
<p id="error">enter correct value!</p>
34+
>>>>>>> 0cc9f2281468d906974b94204367c2cebec1de7f
2435
</div>
2536
</div>
2637
<div class="wrapper">
@@ -31,7 +42,7 @@ <h2>Selective Sorting</h2>
3142
</ul>
3243
</div>
3344
<div class="Before-After">
34-
<p>After Sorting</p>
45+
<p>Your Numbers After Sorting</p>
3546
<ul class="After">
3647
---
3748
</ul>

‎js/app.js‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ const resetBtn = $.querySelector('#reset')
1111
let numbers = []
1212

1313
addNumberBtn.addEventListener('click', () => {
14+
errorElem.style.opacity = '0'
1415
pushNumberToDom()
1516
})
1617

1718
inputElem.addEventListener('keypress', event => {
19+
errorElem.style.opacity = '0'
1820
if (event.key === 'Enter') {
1921
pushNumberToDom()
2022
}
@@ -52,16 +54,26 @@ const findSmallest = arr => {
5254
}
5355

5456
const selectionSort = arr => {
55-
newArr = []
57+
if (numbers.length > 0) {
58+
newArr = []
5659

57-
for (let i = 0; arr.length != 0; i++) {
58-
smallest = findSmallest(arr)
59-
newArr.push(smallest)
60-
smallestIndex = arr.findIndex(num => { return num === smallest })
61-
arr.splice(smallestIndex, 1)
60+
for (let i = 0; arr.length != 0; i++) {
61+
smallest = findSmallest(arr)
62+
newArr.push(smallest)
63+
smallestIndex = arr.findIndex(num => { return num === smallest })
64+
arr.splice(smallestIndex, 1)
65+
}
66+
afterGenerator(newArr)
67+
errorElem.style.opacity = '0'
68+
} else {
69+
errorElem.style.opacity = '1'
70+
errorElem.innerHTML = "basket is empty, add numbers for start!"
6271
}
72+
<<<<<<< HEAD
6373
afterGenerator(newArr)
6474
errorElem.style.display = 'none'
75+
=======
76+
>>>>>>> 0cc9f2281468d906974b94204367c2cebec1de7f
6577
}
6678

6779
const afterGenerator = newArr => {

‎style.css‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ button {
2626
width: 100px;
2727
height: 30px;
2828
border-style: none;
29+
cursor: pointer;
2930
border-radius: 5px;
3031
-webkit-border-radius: 5px;
3132
-moz-border-radius: 5px;
@@ -74,6 +75,10 @@ li {
7475
padding: 35px;
7576
row-gap: 10px;
7677
}
78+
.description {
79+
padding: 0.5rem 0 1.5rem 0;
80+
text-align: center;
81+
}
7782
.wrapper {
7883
padding-top: 20px;
7984
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /