fix: reformatted backing array and slice header exercises

This commit is contained in:
Inanc Gumus
2019-02-08 14:10:56 +03:00
parent 04c5e2bec7
commit 23afa88d08
4 changed files with 24 additions and 20 deletions

View File

@ -27,7 +27,7 @@ import (
//
// RESTRICTION
//
// Fix your problem only in the designated area of the code below.
// Fix the problem only in the designated area of the code below.
//
//
// EXPECTED OUTPUT

View File

@ -28,7 +28,7 @@ import (
//
// Original: [pacman mario tetris doom galaga frogger asteroids simcity metroid defender rayman tempest ultima]
//
// Sorted : [pacman mario tetris doom galaga asteroids frogger simcity metroid defender rayman tempest ultima]
// Sorted : [pacman mario tetris doom galaga asteroids frogger simcity metroid defender rayman tempest ultima]
//
//
// HINT:
@ -47,6 +47,7 @@ func main() {
}
fmt.Println("Original:", items)
// ADD YOUR CODE HERE
fmt.Println()
fmt.Println("Sorted :", items)
}

View File

@ -25,17 +25,17 @@ import (
// the same on your own system as well (if you're on 64-bit machine).
//
//
// <<< initial memory usage >>>
// [initial memory usage]
// > Memory Usage: 104 KB
// <<< after declaring an array >>>
// [after declaring an array]
// > Memory Usage: 78235 KB
// <<< after copying the array >>>
// [after copying the array]
// > Memory Usage: 156365 KB
// <<< inside passArray >>>
// [inside passArray]
// > Memory Usage: 234495 KB
// <<< after slicings >>>
// [after slicings]
// > Memory Usage: 234497 KB
// <<< inside passSlice >>>
// [inside passSlice]
// > Memory Usage: 234497 KB
//
// Array's size : 80000000 bytes.
@ -47,16 +47,19 @@ import (
//
// HINTS
//
// I've declared a few function to help you.
// I've declared a few functions to help you.
//
// report function prints the memory usage.
// Just call it with a message that matches to the expected output.
// report function:
// - Prints the memory usage.
// - Just call it with a message that matches to the expected output.
//
// passArray function accepts a [size]int array, so you can pass it
// your array. It automatically prints the memory usage.
// passArray function:
// - Accepts a [size]int array, so you can pass it your array.
// - It automatically prints the memory usage.
//
// passSlice function accepts an int slice, so you can pass it
// your one of your slices. It automatically prints the memory usage.
// passSlice function:
// - Accepts an int slice, so you can pass it one of your slices.
// - It automatically prints the memory usage.
//
// ---------------------------------------------------------
@ -78,14 +81,14 @@ func main() {
// 3. copy the array to a new array (just assign)
// 4. print the memory usage
// 5. pass the array to passArray function
// 5. pass the array to the passArray function
// 6. convert the array to a slice (by slicing)
// 6. convert the one of the arrays to a slice (by slicing)
// 7. slice only the first 1000 elements of the array
// 8. slice only the elements of the array between 1000 and 10000
// 9. print the memory usage
// 10. pass the one of the slices to passSlice function
// 10. pass the one of the slices to the passSlice function
// 11. print the sizes of the arrays and slices
// hint: use the unsafe.Sizeof function
@ -110,6 +113,6 @@ func passSlice(items []int) {
func report(msg string) {
var m runtime.MemStats
runtime.ReadMemStats(&m)
fmt.Printf("<<< %s >>>\n", msg)
fmt.Printf("[%s]\n", msg)
fmt.Printf("\t> Memory Usage: %v KB\n", m.Alloc/1024)
}

View File

@ -57,6 +57,6 @@ func passSlice(items []int) {
func report(msg string) {
var m runtime.MemStats
runtime.ReadMemStats(&m)
fmt.Printf("<<< %s >>>\n", msg)
fmt.Printf("[%s]\n", msg)
fmt.Printf("\t> Memory Usage: %v KB\n", m.Alloc/1024)
}