<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[MergeSort Problem]]></title><description><![CDATA[<p>Mein MergeSort in C funktioniert leider nicht ganz so wie ich das gerne hätte <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /><br />
Könntet ihr mir bitte mal weiter helfen. Ich komme gerade echt nicht mehr weiter oO</p>
<pre><code class="language-cpp">double mergeSort(int *array, unsigned int size){
	clock_t start, ende;

	start = clock();

	mergesort(array, 0, size-1);

	ende = clock();

	return (double)(ende-start)/CLOCKS_PER_SEC;
}

void mergesort(int *array, int p, int r){
	if(p &lt; r){
		printf(&quot;MergeSort(%d, %d);\n&quot;, p, r);
		int q = (p+r) / 2;
		mergesort(array, p, q);
		mergesort(array, q+1, r);
		merge(array, p, q, r);
	}
}

void merge(int *array, int p, int q, int r){
	printf(&quot;Merge(%d, %d, %d);\n&quot;, p, q, r);
	int i, j, k = 0, size = r-p;

	int *b;
	b = malloc(size * sizeof(int));

	for(i = p; i &lt;= r; i++){
		b[k] = array[i];
		++k;
	}

	i = k = p; j = q+1;

	while(i &lt;= q &amp;&amp; j &lt;= r){
		if(b[i] &lt;= b[j])
			array[k++] = b[i++];
		else
			array[k++] = b[j++];
	}

	while(i &lt;= q)
		array[k++] = b[i++];	

	printArray(array, size, 100);

	free(b);
}
</code></pre>
<p>mfg. Dagobert</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/266474/mergesort-problem</link><generator>RSS for Node</generator><lastBuildDate>Thu, 03 Sep 2026 07:14:21 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/266474.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 09 May 2010 18:33:25 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to MergeSort Problem on Sun, 09 May 2010 18:33:25 GMT]]></title><description><![CDATA[<p>Mein MergeSort in C funktioniert leider nicht ganz so wie ich das gerne hätte <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /><br />
Könntet ihr mir bitte mal weiter helfen. Ich komme gerade echt nicht mehr weiter oO</p>
<pre><code class="language-cpp">double mergeSort(int *array, unsigned int size){
	clock_t start, ende;

	start = clock();

	mergesort(array, 0, size-1);

	ende = clock();

	return (double)(ende-start)/CLOCKS_PER_SEC;
}

void mergesort(int *array, int p, int r){
	if(p &lt; r){
		printf(&quot;MergeSort(%d, %d);\n&quot;, p, r);
		int q = (p+r) / 2;
		mergesort(array, p, q);
		mergesort(array, q+1, r);
		merge(array, p, q, r);
	}
}

void merge(int *array, int p, int q, int r){
	printf(&quot;Merge(%d, %d, %d);\n&quot;, p, q, r);
	int i, j, k = 0, size = r-p;

	int *b;
	b = malloc(size * sizeof(int));

	for(i = p; i &lt;= r; i++){
		b[k] = array[i];
		++k;
	}

	i = k = p; j = q+1;

	while(i &lt;= q &amp;&amp; j &lt;= r){
		if(b[i] &lt;= b[j])
			array[k++] = b[i++];
		else
			array[k++] = b[j++];
	}

	while(i &lt;= q)
		array[k++] = b[i++];	

	printArray(array, size, 100);

	free(b);
}
</code></pre>
<p>mfg. Dagobert</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1894800</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1894800</guid><dc:creator><![CDATA[Ipschie]]></dc:creator><pubDate>Sun, 09 May 2010 18:33:25 GMT</pubDate></item><item><title><![CDATA[Reply to MergeSort Problem on Sun, 09 May 2010 18:58:59 GMT]]></title><description><![CDATA[<p>Joa</p>
<p>EDIT:<br />
Ich raffe deine Signatur nicht, erklär mal.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1894804</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1894804</guid><dc:creator><![CDATA[Kóyaánasqatsi]]></dc:creator><pubDate>Sun, 09 May 2010 18:58:59 GMT</pubDate></item><item><title><![CDATA[Reply to MergeSort Problem on Sun, 09 May 2010 18:55:13 GMT]]></title><description><![CDATA[<p>Bist du denn schon einmal mit einem Debugger schrittweise durchgegangen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1894808</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1894808</guid><dc:creator><![CDATA[Janjan]]></dc:creator><pubDate>Sun, 09 May 2010 18:55:13 GMT</pubDate></item><item><title><![CDATA[Reply to MergeSort Problem on Sun, 09 May 2010 19:05:11 GMT]]></title><description><![CDATA[<p>Debugger <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /><br />
Ich hab vor 2 Wochen mit C angefangen, haben vorher in der Uni ein Semester Java gehabt, wenn du mir sagst wie ich mit dem gcc Compiler gescheit Debuggen kann <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /><br />
werde ichs mal versuchen.</p>
<p>mfg. Dagobert</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1894814</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1894814</guid><dc:creator><![CDATA[Ipschie]]></dc:creator><pubDate>Sun, 09 May 2010 19:05:11 GMT</pubDate></item><item><title><![CDATA[Reply to MergeSort Problem on Sun, 09 May 2010 19:07:10 GMT]]></title><description><![CDATA[<p>Google -&gt; &quot;Linux C Debugger&quot;. Je früher du lernst mit dem Debugger umzugehen, desto besser.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1894815</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1894815</guid><dc:creator><![CDATA[Janjan]]></dc:creator><pubDate>Sun, 09 May 2010 19:07:10 GMT</pubDate></item><item><title><![CDATA[Reply to MergeSort Problem on Sun, 09 May 2010 19:13:31 GMT]]></title><description><![CDATA[<p>Ja das ist wohl war, aber dann müsste ich erstmal lernen wie ich auf einem unix sun client software installiere oO</p>
<p>naja wahrscheinlich dauerts wohl noch bis mein MergeSort funzt <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>mfg. Dagobert</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1894818</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1894818</guid><dc:creator><![CDATA[Ipschie]]></dc:creator><pubDate>Sun, 09 May 2010 19:13:31 GMT</pubDate></item><item><title><![CDATA[Reply to MergeSort Problem on Sun, 09 May 2010 19:37:33 GMT]]></title><description><![CDATA[<p>Ipschie schrieb:</p>
<blockquote>
<p>Ja das ist wohl war, aber dann müsste ich erstmal lernen wie ich auf einem unix sun client software installiere oO</p>
</blockquote>
<p>Wenn du einen gcc installiert hast, ist mit an Sicherheit grenzender Wahrscheinlichkeit auch gdb verfügbar.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1894840</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1894840</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Sun, 09 May 2010 19:37:33 GMT</pubDate></item><item><title><![CDATA[Reply to MergeSort Problem on Sun, 09 May 2010 20:57:29 GMT]]></title><description><![CDATA[<p>Okay ich habs jetzt soweit geschafft das er Zahlen bis 80 Sotiert, danach kommt bis 85 ein segmentation fehler, und dannach ist ganz vorbei das ich in andere bereiche schreibe.<br />
Was ist noch falsch?</p>
<pre><code class="language-cpp">void merge(int *array, int p, int q, int r){
	printf(&quot;Merge(%d, %d, %d);\n&quot;, p, q, r);
	int i, j, k = 0, size = r-p;

	int *b;
	b = malloc(size * sizeof(int));			/* Speicherplatz für die auszulagenden Elemente alocieren */

	for(i = p; i &lt;= r; i++){			/* Elemente vom eigentlichem Feld in ein Hilfsfeld kopieren */
		b[k] = array[i];
		++k;
	}

	i = 0;						/* i = 0 -&gt; erstes Element im Hilfsfeld */
	k = p;						/* k -&gt; position im Array, wo eingefügt wird, */
	j = size/2+1;					/* j = erstes Element der 2 Hälfe im Hilfsfeld */
	printf(&quot;i = %d; k = %d, j = %d\n&quot;, i, k, j);
	while(i &lt;= q-p &amp;&amp; j &lt;= size){			/* solange i &lt;= der 2 Hälfe &amp;&amp; j im Feld ist: */
		if(b[i] &lt;= b[j])			/* Gucken welches das kleinere der beiden Teilelemente ist, und ins eignetliche Feld kopieren */
			array[k++] = b[i++];
		else
			array[k++] = b[j++];
	}

	while(i &lt;= q-p)					/* Solange noch Elemente im ersten Teil sind, werden diese hinten dran gehangen */
		array[k++] = b[i++];	

	printArray(b, size, 100);

	free(b);
}
</code></pre>
<p>mfg. Dagobert</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1894881</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1894881</guid><dc:creator><![CDATA[Ipschie]]></dc:creator><pubDate>Sun, 09 May 2010 20:57:29 GMT</pubDate></item><item><title><![CDATA[Reply to MergeSort Problem on Sun, 09 May 2010 21:05:04 GMT]]></title><description><![CDATA[<p>Wie soll man da durchblicken? Benenn mal deine Variablen vernünftig!</p>
<p>Ist dir bewusst, dass Arrays in C bei 0 anfangen? Die Schleifenabbruchbedingungen sehen mir nämlich verdächtig danach aus, dass du eins zu hoch zählst. Da ich aber keine Ahnung habe wofür p, q, r stehen sollen, habe ich keine Ahnung, ob das bei dir wirklich ein Fehler ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1894882</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1894882</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Sun, 09 May 2010 21:05:04 GMT</pubDate></item><item><title><![CDATA[Reply to MergeSort Problem on Sun, 09 May 2010 21:08:47 GMT]]></title><description><![CDATA[<blockquote>
<p>Wie soll man da durchblicken? Benenn mal deine Variablen vernünftig!</p>
</blockquote>
<p>Ich kann auch nur nach uni Vorgaben arbeiten.<br />
Aber:<br />
p = Anfang des Teil des Feldes welcher sortiert werden soll<br />
r = Ende des Teils<br />
q = Mitte des Teils</p>
<p>Das die Arrays bei 0 anfangen ist mir bewusst, jedoch weiß ich nicht wo ich sie falsch behandel denn dann wäre der ganze post überföüssig oO</p>
<p>mfg. Dagobert</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1894885</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1894885</guid><dc:creator><![CDATA[Ipschie]]></dc:creator><pubDate>Sun, 09 May 2010 21:08:47 GMT</pubDate></item><item><title><![CDATA[Reply to MergeSort Problem on Sun, 09 May 2010 21:34:26 GMT]]></title><description><![CDATA[<p>Mindestens die erste while-Schleife ist schon einmal falsch, da b von 0 bis size-1 geht, du über j aber auch auf den Index size zugreifst. Auf gleiche Weise ist die Bedingung für i wahrscheinlich algorithmisch falsch, da q-p bereits über der Mitte ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1894892</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1894892</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Sun, 09 May 2010 21:34:26 GMT</pubDate></item><item><title><![CDATA[Reply to MergeSort Problem on Sun, 09 May 2010 21:41:08 GMT]]></title><description><![CDATA[<p>Man muss nicht zig mal neu Speicher anfordern. Es reicht, wenn man's einmal macht. Und da Du in einem C++ Forum und nicht in einem C Forum fragst, kriegst Du auch etwas von C++ zu sehen.</p>
<pre><code class="language-cpp">/// performs merge sort on the first size elements of array
/// temp points to an array of at least size elements.
void mergesort_internal(int* array, unsigned size, int* temp)
{
  ...Deine Hausaufgabe...
  (meine Lösung hat hier keine 15 Zeilen)
}

/// performs merge sort on the first size elements of array
void mergesort(int* array, unsigned size)
{
  std::vector&lt;int&gt; buffer (size);  // &lt;--- C++
  mergesort_internal(array,size,&amp;buffer[0]);
}
</code></pre>
<p>kk</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1894897</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1894897</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Sun, 09 May 2010 21:41:08 GMT</pubDate></item><item><title><![CDATA[Reply to MergeSort Problem on Mon, 10 May 2010 02:38:48 GMT]]></title><description><![CDATA[<p>Ipschie schrieb:</p>
<blockquote>
<pre><code class="language-cpp">/* Solange noch Elemente im ersten Teil sind, werden diese hinten dran gehangen */
</code></pre>
</blockquote>
<p>sag mal wo kopierst du eigentlich den rest des zweiten Teils oder gibts den nicht. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
<p>lg lolo</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1894922</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1894922</guid><dc:creator><![CDATA[noobLolo]]></dc:creator><pubDate>Mon, 10 May 2010 02:38:48 GMT</pubDate></item></channel></rss>