Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What is going on with this article?

More than 1 year has passed since last update.

@karaimonoOitii

Goでスターリンソート

なぜやろうと思ったか

皆さんご存知のスターリンソートを止まっていたGoとdockerの勉強がてら作成してみます。

ソースコード


package main

import(
  "fmt"
)
func unset(s []int, i int) []int {
  if i >= len(s) {
      return s
  }
  return append(s[:i], s[i+1:]...)
}

func main() {
  stalin := [] int{3, 6, 7, 1, 9, 7, 11, 2}
  fmt.Println(stalin)
  for i := 1; i < len(stalin); i++ {
    fmt.Println("対象:",stalin[i])
    if stalin[i] < stalin[i - 1] {
      stalin = unset(stalin, i)
      fmt.Println("有罪")
    } 
  }
  fmt.Println(stalin)
}

結果

対象: 6
対象: 7
対象: 1
有罪
対象: 7
有罪
対象: 2
有罪
[3 6 7 9 11]

粛清されましたね。
スターリンソートって表現も面白いし、ソートを粛清って言うのも笑っちゃう。

追加
よく見たら全要素見ていないのでまた修正します

0
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
0
Help us understand the problem. What is going on with this article?