Question
about c language Do problems 1 and 2 of Column 5 *problems 1 : comment on the programming style used in this column and in
about c language
Do problems 1 and 2 of Column 5
*problems 1 : comment on the programming style used in this column and in this book in general address issues such as teh variable names, the form and specification of the binary search function the code layout and so forth.
*problems 2: translate the pseucode description of binary search into languages other than c. and build scanffolding to test and debug your implementation how do the language and syste, help and hinder.
Lab:: problems 1 and 2 of Column 5
Instead of commenting on his code, rewrite it so that it adheres to our courses programming standards and guidelines. This should be done with the binary search on page 46. Include all the
assertions found in Section 5.3 and the test scaffolding found in Section 5.4. Note that this has to be done for C and
not for other languages as suggested in problem 2. Instead of commenting on his code, rewrite it so that it adheres to our coursesprogramming standards and guidelines.
This should be done with the binary search on page 46. Include all the
assertions found in Section 5.3 and the test scaffolding found in Section 5.4. Note that this has to be done for C and
not for other languages as suggested in problem 2.
46 PROGRAMMING PEARLS while (scanf("%d %d", &n , &t) for (i = 0; i t 0 x[result] =- We can start with a C program of about two dozen lines: the binarysearch function and the above code in the main function. We should expect to grow the program as we add additional scaffolding postcondition: Most of the pseudocode statements in Section 4.2 translate line-by-line most other languages, for that matter). Where the pseudocode stores a mto answer variable p, the C program will return the value. Replacing the aue in loop with the C infinite loop for (::) yields this code When I type the input line "2 0", the program generates the two-element array with x [O] =0 and x[1 ] 0, then reports (on the next, indented, line) that the result of searching for 0 was that it was in location 0: 2 10 return -1; rest of loop -5 -1 -1 2 15 We can transform that to a while loop by reversing the test: while (1u) f .. rest of loop The typed input is always in italics. The next pair of lines shows that 10 is correc found in location 1. The final six lines describe three correct unsuccessful search The program thus correctly handles all possible searches in an array of two disti elements. As the program passed similar tests on inputs of other sizes, I grew m and more confident of its correctness and more and more bored with this labori hand testing. The next section describes scaffolding to automate this job. return -1; The final program is then int binarysearch(DataType t) return (any) position if t in sorted x[O..n-1] or int 1, u, 1 if t is not present Not all testing proceeds this smoothly. Here is a binary search proposed by eral professional programmers while (1 t*/ u=n-1; /* printf(" %d %d %d ", 1, m, u) ; */ if (x[m]
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