Create a c program that sorts a sequence of positive


C-Programming

Create a C program that sorts a sequence of positive numbers using the bubble sort algorithm in an increasing or decreasing order based on the user's choice. The pseudo code for the bubble sort algorithm is shown below.

function bubblesort( A : list of numbers )
for each i=length(A)-1 to 0
for each j=1 to i
if A[j-1] > A[j]
swap( A[j-1], A[j] )
end if
end for
end for
end function

The program prompts the user for the sequence of numbers to be sorted followed by the sort order. You can assume a maximum of 100 numbers will be entered. You can also assume the user will enter 0 to mark the end of the input.

Program Specification:

1) Have three functions besides main:

a. one that accepts the sequence of numbers

b. one that sorts the sequence of numbers; this function should take three parameters: the sequence of numbers as an array, size of the sequence, and the sorting order

c. a swap function to be called from the sorting function

2) The main function prints the sorted sequence of numbers

3) The program ignores inputs that are negative numbers.

4) You can use the strcmp c string comparison function in this program; strcmp takes two strings as input and returns 0 if the two strings are equal or a non-zero value if the input strings are not equal.

Sample Run of the Program:

C:\> sort
Enter sort order: up
Enter a sequence of numbers: 10 2 1 3 40 20 0
1 2 3 10 20 40

Solution Preview :

Prepared by a verified Expert
C/C++ Programming: Create a c program that sorts a sequence of positive
Reference No:- TGS01712504

Now Priced at $25 (50% Discount)

Recommended (92%)

Rated (4.4/5)