Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Database Systems Introduction To Databases And Data Warehouses

Authors: Nenad Jukic, Susan Vrbsky, Svetlozar Nestorov

1st Edition

1943153191, 978-1943153190

More Books

Students also viewed these Databases questions

Question

Find a basis for span (l - 2x, 2x - x2, 1 - x2, 1 + x2) in P2.

Answered: 1 week ago

Question

BPR always involves automation. Group of answer choices True False

Answered: 1 week ago

Question

What is the message frequency?

Answered: 1 week ago

Question

What is the schedule for this project?

Answered: 1 week ago

Question

Who is responsible for this project?

Answered: 1 week ago