Skip to content

Comments

insertion sort#20

Open
cody-evaluate wants to merge 1 commit intogreen-goo-dao:mainfrom
cody-evaluate:main
Open

insertion sort#20
cody-evaluate wants to merge 1 commit intogreen-goo-dao:mainfrom
cody-evaluate:main

Conversation

@cody-evaluate
Copy link

let values = [2, 1, 5, 6, 1, 7, 0]

insertionSort(values, fun(a: AnyStruct, b: AnyStruct): Int {
return (b as! Int) - (a as! Int)
})

@austinkline
Copy link
Contributor

Forgot to assign folks here, thanks for submitting this! I'll take a look this week 🙏

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's either delete this file or add .DS_Store to .gitignore

Comment on lines +63 to +66
while i < array.length {
arr.append(array[i])
i = i + 1
}
Copy link
Contributor

@bluesign bluesign Jun 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
while i < array.length {
arr.append(array[i])
i = i + 1
}
arr.appendAll(array)

Copy link
Contributor

@bluesign bluesign Jun 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually I guess: var arr = array also works

@bluesign
Copy link
Contributor

thanks a lot, I made a small comment.

this can be also alternative ( as we are adding items to another array ) :

 pub fun insertionSort(_ array: [AnyStruct], _ f: ((AnyStruct, AnyStruct): Int)): [AnyStruct] {

         var arr: [AnyStruct] = []
         for element in array{
            arr.append(element)
            var j = arr.length - 2
            while j >= 0 && f(arr[j + 1], arr[j]) < 0 {
               arr[j + 1] <-> arr[j]
               j = j - 1
            }
         }
         return arr
}

@bjartek
Copy link
Contributor

bjartek commented Dec 15, 2023

status here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants