NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

Veeresh Shukla
6:06 PM (5 minutes ago)
to me

#include <stdio.h>
#include <stdlib.h>
#include<time.h>
void merge(int arr[], int l, int m, int r)
{
int i, j, k;
int n1 = m - l + 1;
int n2 = r - m;

int L[n1], R[n2];

for (i = 0; i < n1; i++)
L[i] = arr[l + i];
for (j = 0; j < n2; j++)
R[j] = arr[m + 1 + j];


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++;
}

while (i < n1) {
arr[k] = L[i];
i++;
k++;
}


while (j < n2) {
arr[k] = R[j];
j++;
k++;
}
}

void mergeSort(int arr[], int l, int r)
{
if (l < r) {
int m = l + (r - l) / 2;
mergeSort(arr, l, m);
mergeSort(arr, m + 1, r);

merge(arr, l, m, r);
}
}
void printArray(int A[], int size)
{
int i;
for (i = 0; i < size; i++)
printf("%d ", A[i]);
printf("n");
}
int main()
{ int n;
int choice;
int arr1[] ={1,2,3,4,5,6,7,8};
int arr2[]={8,7,6,5,4,3,2,1};
int *arr;
int arr_size=8;
int x;
printf("Enter choice n 1.for random n 2.for sorted n3.for reversely sorted");
scanf("n %d",&choice);
switch(choice)
{
case 2:
{arr=arr1;
break;}
case 3:
{arr=arr2;
break;}
case 1:
{printf("Enter the size of the array");
scanf("n%d",&n);
int arr3[n];
arr=arr3;
for(int i=0;i<n;i++)
arr[i]=rand()%200;
arr_size=n;
break;
}}

clock_t start_t, end_t, total_t;

printf("Given array is n");
printArray(arr, arr_size);
start_t=clock();
mergeSort(arr, 0, arr_size - 1);
end_t=clock();
total_t=(double)(end_t - start_t);
printf("nSorted array is n");
printArray(arr, arr_size);
printf("Time in ms is %ld",total_t);
printf("%d",rand()%50);
return 0;
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.