CECS 282
LAB ASSIGNMENT 3
Assigned date: 9/13
Due date: Tuesday 9/17
25 points
1. [15 points] Write a program for sorting a list of integers in ascending order using the bubble sort algorithm.
Requirements
Implement the following functions:
Here is the content of the file data.txt.
9
8
4
7
2
9
5
6
1
3
2. [5 points] Reimpelment a function called bubble_sort that has the following prototype.
bubble_sort(int *array, int size, pointer to a function)
Pre condition
array - a pointer to a an array of size element.
pointer to function - a pointer to a function that compares two values (depending on sorting in ascending order or descending order)
Post condition
Sort the array in ascending or descending based on the the pointer to a function.
Write the main function to perform the following:
GRADING
3. [3 points] Rewrite the problem 1 with the function readData defined below
int readData( int **arr)
arr is a pointer to pointer for storing the integers. The function returns the number of integers.
The function readData reads the list of integers from a file call data.txt into the array arr. The first integer number in the file is the number of intergers. After the first number, the file lists the integers line by line.
4. [2 points] Rewrite the problem 1 with the function readData defined below
int *readData( )
The function returns a pointer that points to the locations with integers reading from the file data.txt.