Hi friends,
I hope everybody is doing fine. I have written this small c program for the merge_sort algorithm. The algorithm that I am following uses the value infinity. My question is, how to use this infinite value in this c program? I haved used a very large value (99999) instead of infinity, but this value would cause the program to fail in case the unsorted array contains a value larger than 99999. Could you help me with thing? You can have a look at my code.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int A[] = {4, 2, 3, 1, 23, 15, 104, 8, 5};
void Merge_Sort(int [], int, int);
void Merge(int [], int, int, int);
int main()
{
int i;
printf("Unsorted array\n\n");
for(i = 0 ; i < 9 ; i++)
{
printf("%d\n",A[i]);
}
Merge_Sort(A,0,8);
printf("\nSorted array\n\n");
for(i = 0 ; i < 9 ; i++)
{
printf("%d\n",A[i]);
}
return 0;
}
void Merge_Sort(int A[], int p, int r)
{
int q;
if(p < r)
{
q = floor((p + r)/2);
Merge_Sort(A, p, q);
Merge_Sort(A, q + 1, r);
Merge(A, p, q, r);
}
return 0;
}
void Merge(int A[], int p, int q, int r)
{
int n1, n2, i, j, k;
n1 = (q - p) + 1;
n2 = r - q;
int L[n1 + 1];
int R[n2 + 1];
for(i = 1 ; i <= n1 ; i++)
{
L[i] = A[(p + i) - 1];
}
for(j = 1 ; j <= n2 ; j++)
{
R[j] = A[q + j];
}
L[n1 + 1] = 99999; // Supposed to be infinity R[n2 + 1] = 99999; // Supposed to be infinity
i = 1;
j = 1;
for(k = p ; k <= r ; k++)
{
if(L[i] <= R[j])
{
A[k] = L[i];
i = i + 1;
}
else
{
A[k] = R[j];
j = j + 1;
}
}
return 0;
}
Looking forward to your wonderful and helpful replies!
Thanks in advance!
Hi all, I'm glad there's a section called UNIX for dummies on this forum cause when it comes to UNIX, I am certainly a dummie. I honestly don't have a clue about 98% of the UNIX commands out there so forgive me if this is a really stupid question.
I'm trying to set up a MySQL server on my Mac... (7 Replies)
Hello, Ive got to amke a script to calculate how many emails are in the servers mailbox, how many times each IP address appears in the mailbox and to search for keywords, tehn produce the results in HTML report. The thing is I dont know where to start and what the best language to use would be.
... (4 Replies)
Hello ,
i am on linux,
and im trying to figure out why my cp command cant copy one file.
I am trying to use variable in which i stored path to location where is file i wish to copy.
$ echo $ORA_ALERT_LOG
/u01/app/oracle/diag/rdbms/ring11/ring11/trace
$
$
$ pwd
/home/oracle
$ cp -p... (2 Replies)
This might be one of the dumbest questions you've got, but please bear with me:
I am a UNIX beginner. I had an test today and I was asked the following question:
Q. How do you put the terminal into sleep indefinitely?
I didn't know the answer, but after I came home, I tried the following... (9 Replies)
I just tried following
ls *.dat|sort -t"_" -k2n,2|while read f1 && read f2; do
awk '{print}' $f1
awk FNR==1'{print $1,$2,$3,$4,$5,"*","*","*" }' OFS="\t" $f2
awk '{print}' $f2
donegot following result
18-Dec-1983 11:45:00 AM 18.692 84.672 0 25.4 24
18-Dec-1983 ... (3 Replies)
I'am writing a program in C language and my code is working perfectly i just need to add a search to it ...
My code lets users add companies, and then display them on screen...
i would like to add a search that allows user to type company name and then displayall its info on the screen !!
THANK... (1 Reply)
I don't know why, but the rendering of my code mucks up the spacing and indentation, despite being correct in the original file. I'm having issues getting the following script to run (specifically the nested script at the end of the docker command near the end of the script; I think I'm not passing... (2 Replies)
Discussion started by: James Ray
2 Replies
LEARN ABOUT OSX
fxprintf_exec
XPRINTF_EXEC(3) BSD Library Functions Manual XPRINTF_EXEC(3)NAME
asxprintf_exec, dxprintf_exec, fxprintf_exec, sxprintf_exec, xprintf_exec, vasxprintf_exec, vdxprintf_exec, vfxprintf_exec, vsxprintf_exec,
vxprintf_exec -- execute-only extensible printf execution
SYNOPSIS
#include <printf.h>
int
asxprintf_exec(char ** restrict ret, printf_comp_t restrict pc, ...);
int
dxprintf_exec(int fd, printf_comp_t restrict pc, ...);
int
fxprintf_exec(FILE * restrict stream, printf_comp_t restrict pc, ...);
int
sxprintf_exec(char * restrict str, size_t size, printf_comp_t restrict pc, ...);
int
xprintf_exec(printf_comp_t restrict pc, ...);
#include <stdarg.h>
int
vasxprintf_exec(char ** restrict ret, printf_comp_t restrict pc, va_list ap);
int
vdxprintf_exec(int fd, printf_comp_t restrict pc, va_list ap);
int
vfxprintf_exec(FILE * restrict stream, printf_comp_t restrict pc, va_list ap);
int
vsxprintf_exec(char * restrict str, size_t size, printf_comp_t restrict pc, va_list ap);
int
vxprintf_exec(printf_comp_t restrict pc, va_list ap);
DESCRIPTION
These functions are execute-only, extensible printf (see xprintf(5)) variants, taking a printf_comp_t structure created by the format string
compilation routine new_printf_comp(3). All these variants behave like their normal printf counterparts (see printf(3)) without 'x' and
``_exec'' in the name (except sxprintf_exec() and vsxprintf_exec() behave like snprintf() and vsnprintf(), respectively).
SEE ALSO printf(3), xprintf_comp(3), xprintf(5)Darwin Aug 19, 2012 Darwin