Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Thank you very much Blindy for your hints. I tried to implement your hints. Now the program doesn't throw errors but the problem is that i can't check if the operation is done correctly with the programm-environment i've to work with. Do you think the code is correct as it is shown below? Also the time it takes is quite less: 11ms. Do I calc this right?</p> <p>Neil Butterworth,... well your're probably right, but I had to start somehow... and I tried my best to do so. Vinko Vrsalovic,... well you're not right ;) I did it step by step but I thought that its better to show you the whole program and all errors at one time. </p> <pre><code>#include &lt;string.h&gt; #include &lt;jni.h&gt; #include &lt;time.h&gt; #include &lt;stdlib.h&gt; long start, finish; static int ARRAY_LENGTH = 500; static int WORD_LENGTH = 4; static int LOOPS = 10; char *values[1000]; static long getTime(void){ struct timeval now; gettimeofday(&amp;now, NULL); return (long)(now.tv_sec*1000 + now.tv_usec/1000); } void sortStringArray(void){ int i, j; for(i = 0; i &lt; ARRAY_LENGTH; i++){ for(j = 0; j &lt; ARRAY_LENGTH-1; j++){ if(strcmp(values[j], values[j+1]) &gt; 0) { char *holder = values[j+1]; values[j+1] = values[j]; values[j] = holder; } } } } char* generateRandomChar(char *aC){ int length = strlen(aC); char randStr[WORD_LENGTH]; int m; for(m = 0; m &lt;WORD_LENGTH; m++){ int randNr = rand()%length; randStr[m] = aC[randNr]; } return strdup(randStr); } void fillStringArray(void) { char *allowedChars = "abcdefghijklmnopqrstuvwxyz"; int k; for(k = 0; k &lt; ARRAY_LENGTH; k++){ char *randStr = generateRandomChar(allowedChars); values[k] = randStr; } } jlong Java_com_example_hellojni_HelloJni_processStringSort( JNIEnv* env, jobject thiz) { start = getTime(); int i; for(i = 0; i &lt; LOOPS; i++){ fillStringArray(); sortStringArray(); } finish = getTime(); return (finish - start); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload