Skip to content

Comments

Hwork1#1

Open
medvedevvu wants to merge 12 commits intomasterfrom
hwork1
Open

Hwork1#1
medvedevvu wants to merge 12 commits intomasterfrom
hwork1

Conversation

@medvedevvu
Copy link
Owner

No description provided.

func main() {
mslice := make([]int, 10)
/* инит slice */
for idx := 0; idx < len(mslice); idx = idx + 1 {
Copy link

Choose a reason for hiding this comment

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

Этот шаг можно было пропустить. По умолчанию будет 0.

}
fmt.Print(mslice)
/* прибавляю 1 к каждому элементу */
for idx := 0; idx < len(mslice); idx = idx + 1 {
Copy link

Choose a reason for hiding this comment

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

== i:=range mslice

slast = arr[:]
fmt.Println(slast)
fmt.Println(slast[0])
copy(slast[0:], slast[1:])
Copy link

Choose a reason for hiding this comment

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

можно просто использовать slast = slast[1:]

ln := len(pslc) - 1
tmp := make([]int, ln)
copy(tmp, pslc[0:i])
copy(tmp[i:], pslc[i+1:])
Copy link

Choose a reason for hiding this comment

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

element := slice[i]
copy(slice[i:], slice[i+1:len(slice)-1])

/*
Когда писал сотрел вот это https://www.youtube.com/watch?v=4MkLnYxpflI
*/
sort.SliceStable( bslice,
Copy link

Choose a reason for hiding this comment

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

Copy link

Choose a reason for hiding this comment

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

Это работает для <2х символов


import "fmt"

func main() {
Copy link

Choose a reason for hiding this comment

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

В целом алгоритм рабочий, но можно было сделать в один проход по слайсу.

return append( ltemp[1:] , ltemp[0:1]... )
}

func f10(ltemp []int , delta int ) []int {
Copy link

Choose a reason for hiding this comment

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

Можно сократить количество append
https://play.golang.org/p/ONUjpZfesSP

fmt.Println(sl1)
fmt.Println(sl2)
sl3 := []int{}
for _, e := range sl1 {
Copy link

Choose a reason for hiding this comment

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

Очень сложный код. Можно сделать в 2 цикла, если не использовать мапы.

Copy link

Choose a reason for hiding this comment

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

Такие вещи разделять на отдельные функции.

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.

2 participants