#include <iostream>
using namespace std;
 
template <typename T, int N>
class Array
{
private:
    T data [N];
public:
    T & operator [] (int i) { return data [i]; }
};
 
template <typename T, int N>
void sort (Array <T, N> & p)
{
    for (int k = 0; k < N; k ++)
    {
        for (int i = 0; i < N-k-1; i ++)
        {
            if (p[i] > p[i+1])
            {
                // prohodime p[i] , p[i+1]
                T tmp = p[i];
                p[i] = p[i+1];
                p[i+1] = tmp;
            }
        }
    }
}
 
template <typename T, int N>
void print (Array <T, N> & p)
{
    cout << "( ";
    for (int i = 0; i < N; i ++)
    {
        cout << p[i];
        if (i+1 < N)
        {
            cout << ", ";
        }
    }
    cout << " )" << endl;
}
 
int main ()
{
    Array <int, 5> d;
 
    int i = 0;
    d[i++] = 7;
    d[i++] = 3;
    d[i++] = 12;
    d[i++] = 5;
    d[i++] = 20;
 
    print (d);
    sort (d);
    print (d);
}
 
zpro/template.txt · Last modified: 2020/10/12 18:20 by 88.103.111.44
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki