You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
Clement Denis 26b3a37cc0 move subjects to folders 4 years ago
..
README.md

README.md

Compact

Instructions

Write a function Compact that takes a pointer to a slice of string as the argument. This function must:

  • Return the number of elements with non-zero value.

  • Compact, i.e., delete the elements with zero-values in the slice.

Expected functions

func Compact(ptr *[]string) int {

}

Usage

Here is a possible program to test your function :

package main

import (
	"fmt"

	piscine ".."
)

const N = 6

func main() {
	a := make([]string, N)
	a[0] = "a"
	a[2] = "b"
	a[4] = "c"

	for _, v := range a {
		fmt.Println(v)
	}

	fmt.Println("Size after compacting:", piscine.Compact(&a))

	for _, v := range a {
		fmt.Println(v)
	}
}

And its output :

student@ubuntu:~/[[ROOT]]/test$ go build
student@ubuntu:~/[[ROOT]]/test$ ./test
a

b

c

Size after compacting: 3
a
b
c
student@ubuntu:~/[[ROOT]]/test$