Skip to content

added the solution...solution seemed to be missing #2

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package main

import "fmt"
import (
"fmt"
"strings"
)

type User struct {
FirstName string
Expand Down Expand Up @@ -48,14 +51,41 @@ func main() {
}

fmt.Println("Unsorted:", users)
bubbleSort(users)

for i := 0; i < len(users); i++ {
bubbleSort(users[:len(users)-i])
}

fmt.Println("Sorted: ", users)

}

func bubbleSort(users []User) {
// Implement this and any other functions you may need
// If you are writing Go code, you can access the first
// and last name like so:
fmt.Println(users[0].FirstName)
fmt.Println(users[0].LastName)

var lngth int = len(users)
var indx1 int = 0
var indx2 int = 1

for indx2 < lngth {
var val1 User = users[indx1]
var val2 User = users[indx2]

if asc(users[indx1], users[indx2]) {
users[indx1] = val2
users[indx2] = val1
}

indx1++
indx2++
}

}

func asc(first User, second User) bool {
if strings.ToLower(first.LastName + first.FirstName) < strings.ToLower(second.LastName + second.FirstName) {
return true
}
return false
}