fix: reformatted backing array and slice header exercises
This commit is contained in:
@ -27,7 +27,7 @@ import (
|
|||||||
//
|
//
|
||||||
// RESTRICTION
|
// 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
|
// EXPECTED OUTPUT
|
||||||
|
@ -28,7 +28,7 @@ import (
|
|||||||
//
|
//
|
||||||
// Original: [pacman mario tetris doom galaga frogger asteroids simcity metroid defender rayman tempest ultima]
|
// 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:
|
// HINT:
|
||||||
@ -47,6 +47,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Original:", items)
|
fmt.Println("Original:", items)
|
||||||
|
// ADD YOUR CODE HERE
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
fmt.Println("Sorted :", items)
|
fmt.Println("Sorted :", items)
|
||||||
}
|
}
|
||||||
|
@ -25,17 +25,17 @@ import (
|
|||||||
// the same on your own system as well (if you're on 64-bit machine).
|
// 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
|
// > Memory Usage: 104 KB
|
||||||
// <<< after declaring an array >>>
|
// [after declaring an array]
|
||||||
// > Memory Usage: 78235 KB
|
// > Memory Usage: 78235 KB
|
||||||
// <<< after copying the array >>>
|
// [after copying the array]
|
||||||
// > Memory Usage: 156365 KB
|
// > Memory Usage: 156365 KB
|
||||||
// <<< inside passArray >>>
|
// [inside passArray]
|
||||||
// > Memory Usage: 234495 KB
|
// > Memory Usage: 234495 KB
|
||||||
// <<< after slicings >>>
|
// [after slicings]
|
||||||
// > Memory Usage: 234497 KB
|
// > Memory Usage: 234497 KB
|
||||||
// <<< inside passSlice >>>
|
// [inside passSlice]
|
||||||
// > Memory Usage: 234497 KB
|
// > Memory Usage: 234497 KB
|
||||||
//
|
//
|
||||||
// Array's size : 80000000 bytes.
|
// Array's size : 80000000 bytes.
|
||||||
@ -47,16 +47,19 @@ import (
|
|||||||
//
|
//
|
||||||
// HINTS
|
// 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.
|
// report function:
|
||||||
// Just call it with a message that matches to the expected output.
|
// - 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
|
// passArray function:
|
||||||
// your array. It automatically prints the memory usage.
|
// - 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
|
// passSlice function:
|
||||||
// your one of your slices. It automatically prints the memory usage.
|
// - 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)
|
// 3. copy the array to a new array (just assign)
|
||||||
// 4. print the memory usage
|
// 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
|
// 7. slice only the first 1000 elements of the array
|
||||||
// 8. slice only the elements of the array between 1000 and 10000
|
// 8. slice only the elements of the array between 1000 and 10000
|
||||||
// 9. print the memory usage
|
// 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
|
// 11. print the sizes of the arrays and slices
|
||||||
// hint: use the unsafe.Sizeof function
|
// hint: use the unsafe.Sizeof function
|
||||||
@ -110,6 +113,6 @@ func passSlice(items []int) {
|
|||||||
func report(msg string) {
|
func report(msg string) {
|
||||||
var m runtime.MemStats
|
var m runtime.MemStats
|
||||||
runtime.ReadMemStats(&m)
|
runtime.ReadMemStats(&m)
|
||||||
fmt.Printf("<<< %s >>>\n", msg)
|
fmt.Printf("[%s]\n", msg)
|
||||||
fmt.Printf("\t> Memory Usage: %v KB\n", m.Alloc/1024)
|
fmt.Printf("\t> Memory Usage: %v KB\n", m.Alloc/1024)
|
||||||
}
|
}
|
||||||
|
@ -57,6 +57,6 @@ func passSlice(items []int) {
|
|||||||
func report(msg string) {
|
func report(msg string) {
|
||||||
var m runtime.MemStats
|
var m runtime.MemStats
|
||||||
runtime.ReadMemStats(&m)
|
runtime.ReadMemStats(&m)
|
||||||
fmt.Printf("<<< %s >>>\n", msg)
|
fmt.Printf("[%s]\n", msg)
|
||||||
fmt.Printf("\t> Memory Usage: %v KB\n", m.Alloc/1024)
|
fmt.Printf("\t> Memory Usage: %v KB\n", m.Alloc/1024)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user