Skip to content

Commit

Permalink
gather input
Browse files Browse the repository at this point in the history
  • Loading branch information
hoangbits committed Jul 10, 2020
1 parent 33ecaba commit 5126261
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
10 changes: 10 additions & 0 deletions c3-m3/assignment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
### Instructions
The goal of this activity is to explore the use of threads by creating a program for sorting integers that uses four goroutines to create four sub-arrays and then merge the arrays into a single array.

### Detail Instruction
Write a program to sort an array of integers. The program should partition the array into 4 parts, each of which is sorted by a different goroutine. Each partition should be of approximately equal size. Then the main goroutine should merge the 4 sorted subarrays into one large sorted array.

The program should prompt the user to input a series of integers. Each goroutine which sorts ¼ of the array should print the subarray that it will sort. When sorting is complete, the main goroutine should print the entire sorted list.

### Review criterialess
Students will receive five points if the program sorts the integers and five additional points if there are four goroutines that each prints out a set of array elements that it is storing.
31 changes: 31 additions & 0 deletions c3-m3/sortRoutine.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package main

import (
"fmt"
)

func main() {
// https://stackoverflow.com/questions/39565055/read-a-set-of-integers-separated-by-space-in-golang
fmt.Println("Please enter moret than 4 integers")
var n int
if m, err := fmt.Scan(&n); m != 1 {
panic(err)
}
fmt.Println("Enter the integerss")
sli := make([]int, n)
ReadN(sli, 0, n)

}

// ReadN dfd
func ReadN(sli []int, i, n int) {
if n == 0 {
return
}
if m, err := fmt.Scan(&sli[i]); m != 1 {
panic(err)
}
// 1,2,3, 4- 3,2,1, 0
// e.g subsequent call when n=4 as initial value
ReadN(sli, i+1, n-1)
}

0 comments on commit 5126261

Please sign in to comment.