Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Task : please help to generate the output of 100, 200 and 300 integers into the 100data.txt file correctly using onlinegdb compiler.Its urgent please do

Task : please help to generate the output of 100, 200 and 300 integers into the 100data.txt file correctly using onlinegdb compiler.Its urgent please do it correctly. i will upvote for sure if it could generate the output of 100,200 &300 integers into the 100data.txt file correctly. Please use onlinegdb compiler and show me the screenshot.

#include  #include  #include  // helper function for quick sort int partition(int arr[], int l, int h) { int pivot = arr[h]; int i = (l - 1); //smaller element index // iterate for array from l to h for (int j = l; j <= h - 1; j++) { // current element smaller than pivot if (arr[j] < pivot) { i++; // swap elements int t = arr[i]; arr[i] = arr[j]; arr[j] = t; } } // swap i+1 and h array index elements int t = arr[i + 1]; arr[i + 1] = arr[h]; arr[h] = t; return (i + 1); } // defination for quicksort function void quickSort(int arr[], int l, int h) { // for left and right index not equal if (l < h) { //pi is partitioning index int pi = partition(arr, l, h); // recursively iterate till array sorted // divide array into two, sort them seperatly quickSort(arr, l, pi - 1); quickSort(arr, pi + 1, h); } } // for merge sort, helper merge void merge(int arr[], int l, int m, int r) { // declare required variables int i, j, k; int n1 = m - l + 1; int n2 = r - m; int L[n1], R[n2]; // copy from L to R for (i = 0; i < n1; i++) L[i] = arr[l + i]; for (j = 0; j < n2; j++) R[j] = arr[m + 1 + j]; // merge temp values back to array i = 0; j = 0; k = l; while (i < n1 && j < n2) { if (L[i] <= R[j]) { arr[k] = L[i]; i++; } else { arr[k] = R[j]; j++; } k++; } // remaining elements of L[] while (i < n1) { arr[k] = L[i]; i++; k++; } // copy the remaining elements of R[] while (j < n2) { arr[k] = R[j]; j++; k++; } } // Actual merge sort function void mergeSort(int arr[], int l, int r) { // for left index less than right if (l < r) { // middle index m int m = l + (r - l) / 2; // Divide into two parts mergeSort(arr, l, m); mergeSort(arr, m + 1, r); // merge both parts merge(arr, l, m, r); } } // Driver program int main(void) { // Use 191022310 as seed for random generator srand(191022310); int i; // Here i am initializing 100 as size. "CHANGE THE INTEGERS TO 200 AND 300 FOR THE UPCOMING TASKS". int size = 100; int arr[size]; // for (int i = 0; i < size; i++) // { // // initializing the array value with unique random integer // arr[i] = rand(); // //printing the num // printf("%d ", arr[i]); // } FILE *file; file=fopen("numbers.txt","r"); if(file==NULL) { printf("Error reading the file "); exit(0); } for(int i=0;i<100;i++) { fscanf(file,"%d",&arr[i]); } for(int i=0;i<100;i++) { if(i%10==0) { printf(" "); } printf("%d ",arr[i]); } printf(" "); // so that merge sort should not get same arr int *array_for_quicksort = arr; // test, implementation sort arr using quicksort clock_t t; t = clock(); // before time quickSort(array_for_quicksort, 0, size - 1); t = clock() - t; //after time double time_taken = ((double)t) / CLOCKS_PER_SEC; // EXECUTION TIME for quick sort //printf(" time taken by quick sort : %f secs ", time_taken ); // // sort arr using merge sort // clock_t t1; // t1 = clock(); // mergeSort(arr, 0, size - 1); // t1 = clock() - t1; // double time_taken1 = ((double)t1) / CLOCKS_PER_SEC; // // EXECUTION TIME for merge sorts // printf("time taken by mergeSort: %f secs ", time_taken1 ); //write the sorted array into a file FILE *fout = fopen("100data.txt","w"); if(file==NULL) { printf("Cannot open the file "); return -1; } fprintf(fout,"QUICKSORT OUTPUT "); for(int i=0;i 

numbers.txt

1811599914 1397213482 1598683489 1780732491 2128936526 1708920366 906893404 442324823 1846672019 1686833919 922635319 691047811 2118335311 89708842 835064804 459357209 684423830 734585104 1280414874 982799551 2027519985 147445321 1924401171 378482188 167491611 502409715 1588564020 947164700 812514489 1362820584 649839259 476630756 612550418 101039100 109879599 594003297 1809959466 1016773003 1036328120 1509147837 556123274 1958963440 52712000 526974938 2048672282 887776804 986332147 585612464 1622361908 119263373 1568412015 1502398246 266708695 1345329538 1880880434 434200306 1847739254 1321960806 1381365006 512770095 537297743 2031204265 989400851 1149848161 2132243366 1099280450 1743851458 1794719184 2116053454 632695931 1156383374 524693080 444175723 1209095374 1051668018 345364357 2096872179 2038000166 930976821 1571750439 9779891 351905188 926665037 276488586 1697234726 660061824 710688893 1397490332 1982022630 2092053899 1910260428 371836725 1975774517 752177631 1521684887 1960534235 1851458082 1118052697 1607769771 1820027888 

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 Management Systems Designing And Building Business Applications

Authors: Gerald V. Post

1st Edition

0072898933, 978-0072898934

More Books

Students also viewed these Databases questions

Question

2. Why has the conflict escalated?

Answered: 1 week ago