Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C program. 1. Using the code below, implement the descending function: /* bubble sort takes in a compare function pointer to call the correct

In C program. 1. Using the code below, implement the descending function:

/* bubble sort takes in a compare function pointer to call the correct function depending on sort type */

void bubbleSort( int n[], int size, int (*compare) (int a, int b))

{ int pass, i, temp; for( pass = 1; pass < size; pass++ ) { 

for( i = 0 ; i < size - 1 ; i++ ) { if ((*compare)( n[i] , n[i+1]) ) { //If not in order, swap

 temp = n[i]; n[i] = n[i+1]; n[i+1] = temp; 

} }

} }

/* returns 1 if not in ascending order */ int ascending (int a, int b){ } return (a > b) ? 1 : 0; 

/* returns 1 if not in descending order */ int descending (int a, int b){ //TODO: add implementation here!

}

2. You are writing a basic program to work with survey data gathered from some field work.

Some of the data lists have 10 values others have 1,000,000 values. Write a COMPLETE PROGRAM that does the following:

  1. Ask the user for the number of data points to work with (you can assume all data points are of type double). Saves that number in an integer variable iSize.

  2. Use malloc() to dynamically allocates a block of memory (an array) large enough to fit the exact number of data points. Make sure the allocation was successful by checking malloc()s return pointer for NULL.

  3. Use a for loop to fill the array by asking the user to enter the values, 1 at a time (1 per line).

  4. Ask the user if they want to sort in ascending or descending order.

    (Note: User can enter 1 for ascending. 2 for descending)

  5. Use the BubbleSort() function implemented above to sort accordingly.

  6. Display the sorted list.

NOTE: Make sure to unallocated the memory (- return it-), using free()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Database Modeling With Neo4j

Authors: Ajit Singh

2nd Edition

B0BDWT2XLR, 979-8351798783

More Books

Students also viewed these Databases questions

Question

What are the main responsibilities of human resource management?

Answered: 1 week ago

Question

9.8 Describe leadership development and its impact

Answered: 1 week ago