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.
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 OPENSOLARIS
qsort
qsort(3C) Standard C Library Functions qsort(3C)NAME
qsort - quick sort
SYNOPSIS
#include <stdlib.h>
void qsort(void *base, size_t nel, size_t width,
int (*compar)(const void *, const void *));
DESCRIPTION
The qsort() function is an implementation of the quick-sort algorithm. It sorts a table of data in place. The contents of the table are
sorted in ascending order according to the user-supplied comparison function.
The base argument points to the element at the base of the table. The nel argument is the number of elements in the table. The width
argument specifies the size of each element in bytes. The compar argument is the name of the comparison function, which is called with two
arguments that point to the elements being compared.
The function must return an integer less than, equal to, or greater than zero to indicate if the first argument is to be considered less
than, equal to, or greater than the second argument.
The contents of the table are sorted in ascending order according to the user supplied comparison function.
USAGE
The qsort() function safely allows concurrent access by multiple threads to disjoint data, such as overlapping subtrees or tables.
EXAMPLES
Example 1 Program sorts.
The following program sorts a simple array:
#include <stdlib.h>
#include <stdio.h>
static int
intcompare(const void *p1, const void *p2)
{
int i = *((int *)p1);
int j = *((int *)p2);
if (i > j)
return(1);
if (i < j)
return (-1);
return(0);
}
int
main()
{
int i;
int a[10] = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
size_t nelems = sizeof (a) / sizeof (int);
qsort((void *)a, nelems, sizeof (int), intcompare);
for (i = 0; i < nelems; i++) {
(void) printf("%d ", a[i]);
}
(void) printf("
");
return(0);
}
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|Interface Stability |Standard |
+-----------------------------+-----------------------------+
|MT-Level |MT-Safe |
+-----------------------------+-----------------------------+
SEE ALSO sort(1), bsearch(3C), lsearch(3C), string(3C), attributes(5), standards(5)NOTES
The comparison function need not compare every byte, so arbitrary data may be contained in the elements in addition to the values being
compared.
The relative order in the output of two items that compare as equal is unpredictable.
SunOS 5.11 6 Dec 2004 qsort(3C)