<?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[Template-funktionen]]></title><description><![CDATA[<p>Hallo,<br />
ich habe hier ein Programm geschrieben, Template-Funktionen.<br />
aber das Programm funktioniert nicht. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
<pre><code>#include &lt;cstdlib&gt; 
#include&lt;iostream&gt;

using namespace std;

template &lt;typename T&gt; 
void zahlen_eingeben(T array[], int n) {
    for(int i=0; i&lt;n; ++i) cin&gt;&gt;array[i]; cout&lt;&lt;endl; }

template &lt;typename T&gt;
void zahlen_generieren(T array[], int n) {
    for(int i=0; i&lt;n; i++) {
        array[i]=rand(); cout&lt;&lt;endl; } 
}
template &lt;typename T&gt; 
void zahlen_ausgeben( T array[],int n) {
    for (int i=0; i&lt;n; ++i) {
        cout&lt;&lt;array[i]&lt;&lt;endl; }
}

template &lt;typename T&gt;
void bubble_sort(T array[],int n) {         // bubble_sort

 for(int i=1; i &lt;n; i++){

   for(int j=0; j&lt;n-1; j++) {

    if(array[j]&gt; array[j+1]) {

     T tmp = array[j+1]; 
     array[j+1] = array[j]; 
     array[j] = tmp;
    }
   }
 }
}

template &lt;typename T&gt;
void insertion_sort( T array[],int n) {       //insertion_sort

 for (int i=1; i &lt;n; i++) {  

 T tmp=array[i]; 
 int j = i-1; 
 while (j&gt;=0 &amp;&amp; tmp&lt;array[j]) {
     array[j+1] = array[j]; j--; }
 array[j+1] = tmp; 
 }
}

template &lt;typename T&gt; 
void selection_sort( T array[],int n){      //selection_sort

 for (int i=0; i &lt;n-1; i++) { 

 int k=i; // Index kleinstes Element T
int min = array[i]; // kleinstes Element
 for (int j=i+1; j&lt;n; j++) { // suche kleinstes Element

  if (array[j] &lt; min) {
      k = j; min = array[j]; 
  }
 } 
 array[k] = array[i]; // vertausche aktuelles Element mit kleinstem Element
 array[i] = min; 
 }
}

template &lt;typename T&gt; 
void binary_insertion_sort ( T array[], int n/* the size of array */) {  //binary_insertion_sort
    int j,i;
    for ( i = 0; i &lt; n; i++) { 
        T temp = array[i];
        int low = 0, high = i,k;
        while (high&gt;low) {
            int mid = (high + low) / 2;

if ( temp &lt;= array[mid]) high = mid;
else low = mid+1; }
        for (k = i; k &gt; high; k--)
            array[k] = array[k - 1]; 
        array[high] = temp; 
    }
}

int main(){
    int number; 
    int a; 
    int k[];
    do {

            cout&lt;&lt;&quot;(1)Zahlen per Hand eingeben&quot;&lt;&lt;endl;
            cout&lt;&lt;&quot;(2) Zahlen generieren lassen&quot;&lt;&lt;endl; 
            cout&lt;&lt;&quot;(3)Zahlen ausgeben&quot;&lt;&lt;endl; 
            cout&lt;&lt;&quot;(4) Bubble Sort&quot;&lt;&lt;endl;
            cout&lt;&lt;&quot;(5) Insertion Sort&quot;&lt;&lt;endl;
            cout&lt;&lt;&quot;(6) Selection Sort&quot;&lt;&lt;endl;
            cout&lt;&lt;&quot;(7) Binary Insertion Sort&quot;&lt;&lt;endl;
            cout&lt;&lt;&quot;(0) Ende&quot;&lt;&lt;endl;
            cin&gt;&gt;number;
            switch(number) { 
                case 1: { 
                    cout&lt;&lt;&quot;wie viel zahlen :\n&quot;&lt;&lt;endl; 
                    cin&gt;&gt;k; 
                    cout&lt;&lt;endl; 
                    zahlen_eingeben(a,k); 
                    break; 
                } 
                case 2: { 
                    cout&lt;&lt;&quot;wie viel zahlen :\n&quot;&lt;&lt;endl; 
                    cin&gt;&gt;k; 
                    cout&lt;&lt;endl;
                    zahlen_generieren(a,k);
                    break; 
                } 
                case 3: { 
                    cout&lt;&lt;endl;
                    zahlen_ausgeben(a,k); 
                    break;
                }
                case 4: { 
                    bubble_sort(a,k);
                    break; 
                }
                case 5: {
                    insertion_sort(a,k);
                    break;
                }
                case 6: {
                    selection_sort(a,k);
                    break;
                }
                case 7: {
                    binary_insertion_sort (a,k);
                    break;
                }
                case 0: return 0;
            }
    }
    while( number&lt;8);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/323163/template-funktionen</link><generator>RSS for Node</generator><lastBuildDate>Thu, 16 Jul 2026 09:14:43 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/323163.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 20 Jan 2014 07:54:33 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Template-funktionen on Mon, 20 Jan 2014 07:54:33 GMT]]></title><description><![CDATA[<p>Hallo,<br />
ich habe hier ein Programm geschrieben, Template-Funktionen.<br />
aber das Programm funktioniert nicht. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
<pre><code>#include &lt;cstdlib&gt; 
#include&lt;iostream&gt;

using namespace std;

template &lt;typename T&gt; 
void zahlen_eingeben(T array[], int n) {
    for(int i=0; i&lt;n; ++i) cin&gt;&gt;array[i]; cout&lt;&lt;endl; }

template &lt;typename T&gt;
void zahlen_generieren(T array[], int n) {
    for(int i=0; i&lt;n; i++) {
        array[i]=rand(); cout&lt;&lt;endl; } 
}
template &lt;typename T&gt; 
void zahlen_ausgeben( T array[],int n) {
    for (int i=0; i&lt;n; ++i) {
        cout&lt;&lt;array[i]&lt;&lt;endl; }
}

template &lt;typename T&gt;
void bubble_sort(T array[],int n) {         // bubble_sort

 for(int i=1; i &lt;n; i++){

   for(int j=0; j&lt;n-1; j++) {

    if(array[j]&gt; array[j+1]) {

     T tmp = array[j+1]; 
     array[j+1] = array[j]; 
     array[j] = tmp;
    }
   }
 }
}

template &lt;typename T&gt;
void insertion_sort( T array[],int n) {       //insertion_sort

 for (int i=1; i &lt;n; i++) {  

 T tmp=array[i]; 
 int j = i-1; 
 while (j&gt;=0 &amp;&amp; tmp&lt;array[j]) {
     array[j+1] = array[j]; j--; }
 array[j+1] = tmp; 
 }
}

template &lt;typename T&gt; 
void selection_sort( T array[],int n){      //selection_sort

 for (int i=0; i &lt;n-1; i++) { 

 int k=i; // Index kleinstes Element T
int min = array[i]; // kleinstes Element
 for (int j=i+1; j&lt;n; j++) { // suche kleinstes Element

  if (array[j] &lt; min) {
      k = j; min = array[j]; 
  }
 } 
 array[k] = array[i]; // vertausche aktuelles Element mit kleinstem Element
 array[i] = min; 
 }
}

template &lt;typename T&gt; 
void binary_insertion_sort ( T array[], int n/* the size of array */) {  //binary_insertion_sort
    int j,i;
    for ( i = 0; i &lt; n; i++) { 
        T temp = array[i];
        int low = 0, high = i,k;
        while (high&gt;low) {
            int mid = (high + low) / 2;

if ( temp &lt;= array[mid]) high = mid;
else low = mid+1; }
        for (k = i; k &gt; high; k--)
            array[k] = array[k - 1]; 
        array[high] = temp; 
    }
}

int main(){
    int number; 
    int a; 
    int k[];
    do {

            cout&lt;&lt;&quot;(1)Zahlen per Hand eingeben&quot;&lt;&lt;endl;
            cout&lt;&lt;&quot;(2) Zahlen generieren lassen&quot;&lt;&lt;endl; 
            cout&lt;&lt;&quot;(3)Zahlen ausgeben&quot;&lt;&lt;endl; 
            cout&lt;&lt;&quot;(4) Bubble Sort&quot;&lt;&lt;endl;
            cout&lt;&lt;&quot;(5) Insertion Sort&quot;&lt;&lt;endl;
            cout&lt;&lt;&quot;(6) Selection Sort&quot;&lt;&lt;endl;
            cout&lt;&lt;&quot;(7) Binary Insertion Sort&quot;&lt;&lt;endl;
            cout&lt;&lt;&quot;(0) Ende&quot;&lt;&lt;endl;
            cin&gt;&gt;number;
            switch(number) { 
                case 1: { 
                    cout&lt;&lt;&quot;wie viel zahlen :\n&quot;&lt;&lt;endl; 
                    cin&gt;&gt;k; 
                    cout&lt;&lt;endl; 
                    zahlen_eingeben(a,k); 
                    break; 
                } 
                case 2: { 
                    cout&lt;&lt;&quot;wie viel zahlen :\n&quot;&lt;&lt;endl; 
                    cin&gt;&gt;k; 
                    cout&lt;&lt;endl;
                    zahlen_generieren(a,k);
                    break; 
                } 
                case 3: { 
                    cout&lt;&lt;endl;
                    zahlen_ausgeben(a,k); 
                    break;
                }
                case 4: { 
                    bubble_sort(a,k);
                    break; 
                }
                case 5: {
                    insertion_sort(a,k);
                    break;
                }
                case 6: {
                    selection_sort(a,k);
                    break;
                }
                case 7: {
                    binary_insertion_sort (a,k);
                    break;
                }
                case 0: return 0;
            }
    }
    while( number&lt;8);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2378445</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2378445</guid><dc:creator><![CDATA[kadour]]></dc:creator><pubDate>Mon, 20 Jan 2014 07:54:33 GMT</pubDate></item><item><title><![CDATA[Reply to Template-funktionen on Mon, 20 Jan 2014 07:56:29 GMT]]></title><description><![CDATA[<p>kadour schrieb:</p>
<blockquote>
<p>aber das Programm funktioniert nicht. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
</blockquote>
<p>Haste Nasendämonen? Oder wie äußert sich das? Meckert der Comiler, der Linker, das Laufzeitsystem? Und wie sieht die Mecker aus?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2378446</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2378446</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Mon, 20 Jan 2014 07:56:29 GMT</pubDate></item><item><title><![CDATA[Reply to Template-funktionen on Mon, 20 Jan 2014 08:00:20 GMT]]></title><description><![CDATA[<p>hatte nun keine lust den ganzen code im detail anzuschauen. nur zwei dinge auf die kürze:<br />
1.</p>
<pre><code>int k[];
</code></pre>
<p>dass das nicht geht ist logisch. wie gross soll das array denn sein?<br />
2. wenn du schon mit templates arbeitest dann kannst du doch gleich das iterator-pattern verwenden. ist viel besser als das was du hier machst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2378447</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2378447</guid><dc:creator><![CDATA[Fytch]]></dc:creator><pubDate>Mon, 20 Jan 2014 08:00:20 GMT</pubDate></item><item><title><![CDATA[Reply to Template-funktionen on Mon, 20 Jan 2014 10:58:20 GMT]]></title><description><![CDATA[<blockquote>
<p>dass das nicht geht ist logisch.</p>
</blockquote>
<p>Das ist erlaubt, seit C++14.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2378466</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2378466</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Mon, 20 Jan 2014 10:58:20 GMT</pubDate></item><item><title><![CDATA[Reply to Template-funktionen on Mon, 20 Jan 2014 11:11:55 GMT]]></title><description><![CDATA[<p>Arcoth schrieb:</p>
<blockquote>
<blockquote>
<p>dass das nicht geht ist logisch.</p>
</blockquote>
<p>Das ist erlaubt, seit C++14.</p>
</blockquote>
<p>kann man das denn schon so definitiv sagen? es ist doch bestimmt nur in einem wd vorgeschlagen worden, nicht jedoch fix im standard verankert. und hast du dazu zufällig ein paper oder so zur hand? es nimmt mich schon wunder was das bedeutet etc. und ich hab bedauerlicherweise auf die schnelle nichts entsprechendes gefunden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2378470</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2378470</guid><dc:creator><![CDATA[Fytch]]></dc:creator><pubDate>Mon, 20 Jan 2014 11:11:55 GMT</pubDate></item></channel></rss>