Movatterモバイル変換


[0]ホーム

URL:


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

Refactor the code#1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
WaithakaGuru merged 1 commit intoMajorfromSelectionSort-Edit
May 9, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletionsbubbleSort.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
// on 26th August 2024 [12:06 PM ]
//function to perform bubble sort

// a simple function to return the length of an iterable eg an ARRAY, STRING, e.t.c
function count(iterable){
Expand All@@ -10,7 +9,6 @@ function count(iterable){
}

/* the bubble sort logic function*/

function bubbleSort(array){
let iterations = sort(array), iterationsCount =[];
while(iterations.swaps > 0){
Expand All@@ -31,8 +29,11 @@ function bubbleSort(array){
}
}

//testing the function
console.log(bubbleSort([22,3,44,5,6,8,7,10,9,15]));// normal list
console.log(bubbleSort([1,3,2,4,4,5,6,7,8,9])); // list with only one misplaced element
console.log(bubbleSort([13,12,11,9,8,7,6,5,3,2])); // a reverse-ordered list
console.log(bubbleSort([10,11,22,33,44,55,66,77,88,99])); // a sorted list
/**
* Testing the Algo with a normal unordered, ordered, reverse ordered lists
* and a list with only one misplaced element
*/
console.log(bubbleSort([22,3,44,5,6,8,7,10,9,15]));
console.log(bubbleSort([1,3,2,4,4,5,6,7,8,9]));
console.log(bubbleSort([13,12,11,9,8,7,6,5,3,2]));
console.log(bubbleSort([10,11,22,33,44,55,66,77,88,99]));
2 changes: 1 addition & 1 deletioninsertionSort.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
// On the evening of 26th August 2024
// creating an insertion Sort algorithm

// a function to get the length of an iterable eg ARRAY, STRING e.t.c
function count (iterable){
Expand All@@ -8,6 +7,7 @@ function count (iterable){
for(const item of iterable) i++;
return i;
}

// the Insertion sort logic
function insertionSort(array){
let sorted= [], len = count(array), temp, swaps = 0, swapsCount= [], iterations = 0;
Expand Down
27 changes: 11 additions & 16 deletionsquickSort.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
// Now into Advanced sorting algorithms am going to code the
// quick sort Algorithm (it's a recursive one) On 28th August 2024 [ 10:47 PM ]
import { quickSort } from "./allSortAlogs";
// fn to calc the length of a list of items ie(no of items in a list)
// fn to calc the length of a list of items
function count(iterable){
if(!isNaN(iterable)) iterable = `${iterable}`;
let i = 0;
for(const item of iterable) i++;
return i;
}
function rangeCount(iterable, start, end){
if(!isNaN(iterable)) iterable = `${iterable}`;
let i = 0;
for( j = start; j<=end; j++) i++;
return i;
}
// quick sort logic

// quick sort Algorithm (it's a recursive one) On 28th August 2024 [ 10:47 PM ]
function quickSort(list=[], start =0 ,end= count(list) - 1){
if(start < end){
let pivotIndex = partition(list, start, end);
Expand All@@ -35,8 +27,11 @@ function partition(list, start, end){
return i+1;
}

// testing the function
console.log(quickSort([1,3,2,4,4,5,6,7,8,9])); // list with only one misplaced element
console.log(quickSort([13,12,11,9,8,7,6,5,3,2])); // a reverse-ordered list
console.log(quickSort([10,11,22,33,44,55,66,77,88,99])); // a sorted list
console.log(quickSort([22,3,44,5,6,8,7,10,9,15]));// normal list
/**
* Testing the Algo with a normal unordered, ordered, reverse ordered lists
* and a list with only one misplaced element
*/
console.log(quickSort([1,3,2,4,4,5,6,7,8,9]));
console.log(quickSort([13,12,11,9,8,7,6,5,3,2]));
console.log(quickSort([10,11,22,33,44,55,66,77,88,99]));
console.log(quickSort([22,3,44,5,6,8,7,10,9,15]));
19 changes: 9 additions & 10 deletionsselectionSort.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
console.log("Still on 31st July" + " Let's continue coding");
/* --SELECTION SORT--
*
*
*/
// --SELECTION SORT-

// fn to give the length of the List of items (i.e no of items)
function count(iterable){
if(!isNaN(iterable)) iterable = `${iterable}`;
let i = 0;
Expand All@@ -28,7 +23,11 @@ function selectionSort (list){
}
return [list, `No of checks done per iteration: ${checksCount}`, `No of iterations for complete sort ${iterations}`]
}
console.log(selectionSort([1,3,2,4,4,5,6,7,8,9])); // list with only one misplaced element
console.log(selectionSort([13,12,11,9,8,7,6,5,3,2])); // a reverse-ordered list
console.log(selectionSort([10,11,22,33,44,55,66,77,88,99])); // a sorted list
console.log(selectionSort([22,3,44,5,6,8,7,10,9,15]));// normal list
/**
* Testing the Algo with a normal unordered, ordered, reverse ordered lists
* and a list with only one misplaced element
*/
console.log(selectionSort([1,3,2,4,4,5,6,7,8,9]));
console.log(selectionSort([13,12,11,9,8,7,6,5,3,2]));
console.log(selectionSort([10,11,22,33,44,55,66,77,88,99]));
console.log(selectionSort([22,3,44,5,6,8,7,10,9,15]));

[8]ページ先頭

©2009-2025 Movatter.jp