Sponsored Content
Top Forums Programming Representing INFINITY in C language???? Post 302599778 by gabam on Saturday 18th of February 2012 09:18:50 AM
Old 02-18-2012
Representing INFINITY in C language????

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!
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

A different language to me!

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)
Discussion started by: kguenther
7 Replies

2. Programming

c language

is there any difference between "char*" and "char *" (1 Reply)
Discussion started by: amol munde
1 Replies

3. Programming

which language will be the best

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)
Discussion started by: clueless
4 Replies

4. UNIX for Dummies Questions & Answers

What language is this?

Hi, Just got handed this script set def = HLA_DR.pockets set data = DRB1_1501.dat foreach a ( 'cat $data | args 3 |sort -u' ) cat $def | xC | grep -v $a > $$.def cat $data | grep $a | args 1,2 > $a.dat set pseudo = `cat MHCDR_pseudo.dat | grep HLA | grep $a | args 2`... (8 Replies)
Discussion started by: lost
8 Replies

5. Shell Programming and Scripting

Representing dir path for copy through env variable

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)
Discussion started by: tonijel
2 Replies

6. UNIX for Dummies Questions & Answers

sleep infinity

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)
Discussion started by: indyxandy
9 Replies

7. Shell Programming and Scripting

File representing the hard disk storage device

I want example of a file representing the hard disk storage device In UNIX ? (6 Replies)
Discussion started by: tamer11007
6 Replies

8. Shell Programming and Scripting

awk Merging multiple files with symbol representing new file

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)
Discussion started by: Akshay Hegde
3 Replies

9. Programming

C language help URGENT !!!

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)
Discussion started by: aloushi
1 Replies

10. UNIX for Beginners Questions & Answers

Can't pass a variable representing the output of lsb_release to a docker dontainer

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
crypt_unix(5)						Standards, Environments, and Macros					     crypt_unix(5)

NAME
crypt_unix - traditional UNIX crypt algorithm DESCRIPTION
The crypt_unix algorithm is the traditional UNIX crypt algorithm. It is not considered sufficiently secure for current systems and is pro- vided for backwards compatibility. The crypt_sunmd5(5), crypt_bsdmd5(5), or crypt_bsdbf(5) algorithm should be used instead. The algorithm identifier for policy.conf(4) is __unix__. There is no entry in crypt.conf(4) for this algorithm. The crypt_unix algorithm is internal to libc and provides the string encoding function used by crypt(3C) when the first character of the salt is not a "$". This algorithm is based on a one-way encryption algorithm with variations intended (among other things) to frustrate use of hardware imple- mentations of a key search. Only the first eight characters of the key passed to crypt() are used with this algorithm; the rest are silently ignored. The salt is a two-character string chosen from the set [a-zA-Z0-9./]. This string is used to perturb the hashing algo- rithm in one of 4096 different ways. The maximum password length for crypt_unix is 8 characters. USAGE
The return value of the crypt_unix algorithm might not be portable among standard-conforming systems. See standards(5). ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |MT-Level |Safe | +-----------------------------+-----------------------------+ SEE ALSO
passwd(1), crypt(3C), crypt_genhash_impl(3C), crypt_gensalt(3C), crypt_gensalt_impl(3C), getpassphrase(3C), crypt.conf(4), passwd(4), pol- icy.conf(4), attributes(5), crypt_bsdbf(5), crypt_bsdmd5(5), crypt_sunmd5(5), standards(5) SunOS 5.10 6 Aug 2003 crypt_unix(5)
All times are GMT -4. The time now is 10:55 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy