Question
Write a small program in the Go language that implements a simple linear search function and tests it. Two example implementations in C and JavaScript
Write a small program in the Go language that implements a simple linear search function and tests it. Two example implementations in C and JavaScript are provided. Your solution should mimic these programs, and produce very similar output.1 In particular: Implement 3 functions: main, test, and search. (Note that the JavaScript program does not use a separate main function, but the C program does and your Go programs will.) Use the same test array (values 5,3,9,11,71) and test strategy (try to find each value in the array, and one value that is not in the array). Note that the C version passes an explicit array length value to test() and search(), while the JavaScript does not. This is because JavaScript can check array sizes while C cant. Go, like JavaScript, can check array sizes, so you will not need the explicit size parameter to these two functions. Your Go search function should be different from the two provided examples on one key aspect: it must return two values. The C/JavaScript search function returns a single integer that is the index of the located value; if the value is not found then -1 is returned. This is bad programming as the single return value has two meanings: a value found indicator and an array index. Go (like Haskell) can return multiple values. You should use a Go function declaration like func search(a []int, val int) (found bool, key int) that returns a found value (true or false) as well as the index (key) value. If the index is not found you can return any value for key as it will not be used. Include a listing of the program in the assignment submission. I will not be compiling and executing the code, so dont submit a separate source file. All you need to know about Go is at the language web site https://golang.org/. If you wish you can download and install the Go system as documented there. (Linux users can simply install the Go package: golang)
C example2 #include JavaScript example3
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started