Advertisement
Guest User

pipesort2_en_go

a guest
May 24th, 2019
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.10 KB | None | 0 0
  1.  
  2.  
  3.  
  4. package main
  5.  
  6.  
  7. import (
  8.  
  9.     "fmt"
  10.     "math/rand"
  11. )
  12. func pipesort(in, out chan int, i int, s []int)
  13. {
  14.     /*Necesito una forma en cual leer los datos, leo todos los numeros en el canal de entreada, si es el primer numero que estoy leyendo, el menor va  a ser el num*/
  15.  
  16.     first := true
  17.     var min int
  18.     for num:= range in{
  19.         if first{
  20.             first = false
  21.             min = num
  22.         }
  23.         else if num < min{
  24.             out <- min
  25.             min = num
  26.         }else{
  27.             out<-num
  28.         }
  29.     }
  30.     close(out)
  31.     s[i]= min
  32. }
  33.  
  34. func main(){
  35.     n:= 10
  36.     /*slice de canales simples*/
  37.     ch := make([] chan int, n+1) /*tenemos n +1 canales*/
  38.     /*inicio el canal en un proceso desatendido*/
  39.     ch[0]= make(chan int)
  40.     go func(ch chan int){
  41.         for i := 0; i<n ; i++
  42.         {
  43.             ch<-rand.Intn(100)   /*ch toma la primera variable  que esta fuera de la func*/
  44.         }
  45.         /*eclipse de variable*/
  46.     }(ch[0]) /*ch recibe el registro de lo que le estamos enviando, tengo dos variables ch uno dentro y fuera*/
  47.  
  48.     s:= make([]int, n)
  49.  
  50.     for i:= 0; i<n ; i++{
  51.         ch[i+1] = make(chan int)
  52.         go pipesort(ch[i],ch[i+1],i,s)
  53.     }
  54.  
  55.     for _ = range ch[n]{
  56.     }
  57.     fmt.Println(s)
  58. }
  59. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement