Question: Programming in C. A simple bubble sort algorithm is attached for your reference. Remember in your code, you have to open 2 files: an input

Programming in C. A simple bubble sort algorithm is attached for your reference. Remember in your code, you have to open 2 files: an input file to read "Lab3.dat" data, and an output file to write your sorted array. The Lab3.dat file contains exactly 100 elements in random order, your task is to sort them in ascending order - smallest to greatest. Write a program to open and read from a file (attached Lab3.dat), sort the data in ascending order (smallest to largest), and write the sorted data into an output file. Attached simple bubble sort functions. /* C program for implementation of Bubble sort */ #include void swap(int *xp, int *yp) { int temp = *xp; *xp = *yp; *yp = temp; } /* A function to implement bubble sort */ void bubbleSort(int arr[], int n) { int i, j; for (i = 0; i < n-1; i++) /* Last i elements are already in place */ for (j = 0; j < n-i-1; j++) if (arr[j] > arr[j+1]) swap(&arr[j], &arr[j+1]); } /* Function to print an array */ void printArray(int arr[], int size) { int i; for (i=0; i < size; i++) printf("%d ", arr[i]); printf("n"); } /* Main program to test above functions */ int main(void) { int arr[] = {64, 34, 25, 12, 22, 11, 90}; int n = sizeof(arr)/sizeof(arr[0]); bubbleSort(arr, n); printf("Sorted array: "); printArray(arr, n); return 0; }

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!