Question: This question does not need to be coded, it just needs to be in pseudocode. Like Java or C but you're more just talking through

This question does not need to be coded, it just needs to be in pseudocode. Like Java or C but you're more just talking through what you're doing. Thanks!

6. Writing algorithms (10 points)

Convert Problem 3 Strategy 3 into an algorithm and write it below. remember to provide an algorithm header, number the algorithm steps and to use pseudocode conventions.

Problem Statement: Given an array containing some numbers, reorder those numbers in that array so that any negative numbers appear before any zeroes and any zeroes appear before any positive numbers. Come up with a well-defined problem specification for this.

Strategy 3:

Scan the input array A, counting the number of negative, zero and positive numbers. Let these counts be x, y and z respectively.

Create a new array B of the same size and set a local variable neg to 1, zero to x+1, and pos to x+y+1.

Scan the input array from left to right, and if the current number being looked at is negative, copy it to B[neg] and increment neg, if it is a zero, copy it to B[zero] and increment zero, and if it is positive, copy it to B[pos] and increment pos.

Output array B.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!