#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <iostream>
#include "CPole.h"
#include "CError.h"
using namespace std;
CPole::CPole(int pocet,int dolnyindex) : aPocet(pocet), aDolnyIndex(dolnyindex),
aPole(aPocet>0 ? new double[aPocet] : NULL)
{
printf("CPole()\n");
}
CPole::CPole(const CPole &src) : aPocet(src.aPocet), aDolnyIndex(src.aDolnyIndex),
aPole(aPocet>0 ? new double[aPocet] : NULL)
{
if(aPole != NULL) {
memmove(aPole,src.aPole,aPocet*sizeof(double));
}
}
CPole &CPole::operator = (const CPole &src)
{
if(this != &src) {
if(aPole!=NULL) {
delete[] aPole;
aPocet = 0;
aDolnyIndex = 0;
}
if(src.aPole!=NULL) {
aPocet = src.aPocet;
aDolnyIndex = src.aDolnyIndex;
aPole = new double[aPocet];
memmove(aPole,src.aPole,aPocet*sizeof(double));
}
}
return *this;
}
CPole::~CPole(void)
{
printf("~CPole()\n");
if(aPole!=NULL)
delete[] aPole;
}
double CPole::operator[](int index)
{
if(index<aDolnyIndex || index>aDolnyIndex+aPocet-1) throw CError("Zly index!\n",aDolnyIndex);
else return aPole[index-aDolnyIndex];
}
void CPole::Set(int index, double hodnota)
{
aPole[index-aDolnyIndex] = hodnota;
}
int compare( const void *a, const void *b)
{
int cislo1 = *((int*)a);
int cislo2 = *((int*)b);
if (cislo1 < cislo2) return -1;
if (cislo1 == cislo2) return 0;
return 1;
}
void CPole::AplikujQsort(CPole pole[], int ArraySize)
{
// qsort(pole, ArraySize, sizeof(CPole),Compare);
}
Nevedel by niekto pomoct s qsortom s tym, ze nejde o klasicke pole ale o obalovu triedu pola realnych cisel?
Ak to klasicky qsort qsort((void *)table, TableSize, sizeof(table[0]), sortFunction); tak mi hadze vzdy chybu ... Vopred vdaka