我意识到函数插入动态有序列表,但我不明白为什么它不起作用:(我必须列出手机类,我必须为字母数字代码订购
template<class T>
void lista<T>::insord(T &val) {
nodo<T> *newptr = getnew(val);
nodo<T> *p = firstptr;
nodo<T> *prec = firstptr;
if(isempty())
firstptr = lastptr = newptr;
else {
// while ((p->nextptr != 0) &&
// ((p->data->getnumtel()) > (newptr->data->getnumtel())))
while ((p->nextptr != NULL) &&
(strcmp(p->data->getcod(), newptr->data->getcod()) > 0)) {
prec = p;
p=p->nextptr;
}
if (p->nextptr != NULL) {
// if ((p->data->getnumtel())==(newptr->data->getnumtel()))
if (strcmp(p->data->getcod(),newptr->data->getcod()) == 0)
throw ecc();
newptr->nextptr = p;
prec->nextptr = newptr;
} else {
lastptr->nextptr = newptr;
newptr->nextptr = NULL;
lastptr = newptr;
}
}
}