Question
For this task, you will refresh array access by implementing the simplest sorting algorithm you have learned from your Java programming: bubble sorting. assign2/task5 contains
For this task, you will refresh array access by implementing the simplest sorting algorithm you have learned from your Java programming: bubble sorting. assign2/task5 contains the source code array.c and test code array_test.c. Please implement the bubbleSort function inside array.c, and compile array.c and array_test.c into an executable. array_test.c contains a few simple tests against your bubbleSort. Please make sure your code passes all tests.
array.c
#include
/* function prototypes: */
void printArray(int a[], int size);
void bubbleSort(int a[], int size);
/* prints out the contents of an array
* a: the array of int values
* size: the number of elements in the array
*/
void printArray(int a[], int size) {
// An example of a function that doesn't return a value.
int i;
printf(\"Array Contents: \");
for (i = 0; i
printf(\"%d \", a[i]);
}
printf(\" \");
}
/* review bubble sorting from your java class and implement
* it for a C array, in which elements could be accessed through
* index notation just like Java arrays.
* Precondition:
* a: the array of int values
* size: the number of elements in the array
* returns: nothing
* Postcondition:
* a is sorted in ascending order
*/
void bubbleSort(int a[], int size) {
//TODO: write this function
}
For this task, you will refresh array access by implementing the simplest sorting algorithm you have learned from your Java programming: bubble sorting. assign2/task5 contains the source code array.c and test code array_test.c. Please implement the bubbleSort function inside array.c, and compile array.c and array_test.c into an executable. array_test.c contains a few simple tests against your bubbleSort. Please make sure your code passes all tests.
array.c
#include
/* function prototypes: */
void printArray(int a[], int size);
void bubbleSort(int a[], int size);
/* prints out the contents of an array
* a: the array of int values
* size: the number of elements in the array
*/
void printArray(int a[], int size) {
// An example of a function that doesn't return a value.
int i;
printf(\"Array Contents: \");
for (i = 0; i
printf(\"%d \", a[i]);
}
printf(\" \");
}
/* review bubble sorting from your java class and implement
* it for a C array, in which elements could be accessed through
* index notation just like Java arrays.
* Precondition:
* a: the array of int values
* size: the number of elements in the array
* returns: nothing
* Postcondition:
* a is sorted in ascending order
*/
void bubbleSort(int a[], int size) {
//TODO: write this function
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered 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