class Medicine{
protected:
int id;
int stock;
string name;
int concentration;
public:
Medicine();
Medicine(int id,int s,const string n,int c);
Medicine(const Medicine& m);
Medicine& operator=(const Medicine& m);
virtual ~Medicine();
int getStock() const;
int getConcentration() const;};
模块1排序对象
template<typename T> class Vector
{
private:
T* Elems;
int Size;
int Capacity;
public:
Vector()
~Vector()
void add(T e)
void remove(int pos)
int getSize() const
int getCapacity() const
T get(int pos) const;}
template <typename T>
T Vector<T>::get(int pos) const
{
if (pos < 0 || pos >= this->getSize())
return NULL;
return this->Elems[pos];
}
模块2
class MedRepo :
public:~MedRepo();
void addMed(Medicine s);
void upgrade(Medicine s);
Medicine* findById(int medId) ;
virtual void removeMed(int id) ;
int getNrMeds();
Vector<Medicine*> getAll() ;
protected:
Vector<Medicine*> MedList;
};
模块3
typedef int (*comparefunction)(const void*, const void*);
int compareSA(const Medicine* e1, const Medicine* e2){
int q1 = (*(Medicine **) e1)->getStock();
int q2 = (*(Medicine **) e2)->getStock();
if (q1 < q2){
return -1;
}
else{
if (q1>q2){
return 1;
}
return 0;
}
}
模块4
所以阵列,这是我的代码的一部分,我想要做的就是我的对象相对于一些指标分析排序,其中之一是一个在4 module.I've一直与从本周开始类和我已经找到了一些类似的问题,但我不明白,整个过程大约sorting.I've刚读一些有关std:sort
和std::stable_sort
,但我不知道如何使用它们为我data.All我现在是:
Vector<Medicine*>* Control::sortByStockAsc(){
Vector<Medicine*> all =repo->getAll();
任何意见,建议,帮助吗?
不要告诉我这段代码实际上工作... – dtech 2013-05-11 19:30:01
从这个意义上说,我没有错误/ bug直到现在,是的 – 2013-05-11 19:32:05
@MrMime正如我下面所说的,只需通过成员类型你用。更不用说''Medicine'的析构函数,复制构造函数和赋值运算符几乎毫无意义。 – pmr 2013-05-11 19:33:54