hay un ejercicio que intenté hacer y que no me compila, a pesar de corregir varios fallos tontos, pero la cuestión es que falla debido a (creo yo) errores en el planteamiento.
este el enunciado:
Desarrollar el método template void dll_t::swap(const int i, const int j) que intercambia el valor del atributo data del nodo i-ésimo (nodo en la posición i de la lista) con el nodo j-ésimo.
#pragma once
#include <cassert>
#include <iostream>
#include <cstdio>
#include "dll_node_t.hpp"
using namespace std;
namespace AED {
template <class T>
class dll_t {
private:
dll_node_t<T>* head_;
dll_node_t<T>* tail_;
int sz_;
public:
dll_t(void);
dll_t(const dll_t& L);
virtual ~dll_t(void);
void insert_tail(dll_node_t<T>*);
void insert_head(dll_node_t<T>*);
dll_node_t<T>* extract_tail(void);
dll_node_t<T>* extract_head(void);
dll_node_t<T>* get_tail(void);
dll_node_t<T>* get_head(void);
bool empty(void) const ;
int get_nz (void) const{}
void unlink(dll_node_t<T>*);
dll_node_t<int>* find (const int v);
void dll_union (dll_t<int>& A, dll_t<int>& B, dll_t<int>& C);
int get_size(void) const;
void swap (const int i,const int j);
// esto: contar los nonzeros
//modif: suma elementos matriz
//double suma (void) const; // esto pa arriba
//int get_np (void) const;
//double suma_mat (void) const;
void invert(void);
ostream& write(ostream& os) const;
};
template<class T>
void dll_t<T>::swap(const int i,const int j){
dll_node_t<T>* aux = NULL;
dll_node_t<T>* auxi = get_data();
dll_node_t<T>* auxj = get_data();
while(aux != NULL){
while(auxi != NULL && auxj!=NULL){
auxi->get_data()=aux;
auxi->get_data() = aux->get_data();
aux = auxj ->get_data();
auxj = auxj -> get_next();
auxi = auxi -> get_next();
}
aux = aux -> get_next();
}
}
template<class T>
void dll_t<int>::dll_union (dll_t<int>& A, dll_t<int>& B, dll_t<int>& C){
dll_node_t<int>* aux1 = A.get_head();
dll_node_t<int>* aux2 = B.get_head();
while (aux2 != NULL || aux1 != NULL){
if (B.find((aux1->get_data()))){
C.insert_tail(aux1);
}
if((aux1->get_data()) != (aux2->get_data())){
C.insert_tail(aux1);
C.insert_tail(aux2);
}
aux2=aux2->get_next();
aux1=aux1->get_next();
}
}
template<class T>
dll_node_t<int>* dll_t<int> :: find(const int v){
assert(!empty());
dll_node_t <int>* aux = get_head();
dll_node_t <int>* encontrado = NULL;
while(aux !=NULL){
if ((aux -> get_data())== v){
encontrado= aux;
}
aux = aux-> get_next();
}
return encontrado;
}
template<class T>
void dll_t<T> :: invert(void){
assert(!empty());
dll_node_t<T>* aux = get_tail();
while (aux != NULL){
extract_tail(aux);
aux = aux -> get_prev();
}
while (aux !=NULL){
insert_tail(aux);
aux=aux->get_next();
}
}
template <class T>
dll_t<T>::dll_t(void) :
head_(NULL),
tail_(NULL),
sz_(0) {
}
template <class T>
dll_t<T>::dll_t(const dll_t& L) :
head_(NULL),
tail_(NULL),
sz_(0) {
dll_node_t<T>* aux = L.head_;
while (aux != NULL) {
insert_tail(new dll_node_t<T>(aux->get_data()));
aux = aux->get_next();
}
}
template <class T>
dll_t<T>::~dll_t(void) {
dll_node_t<T>* aux = NULL;
while (head_ != NULL) {
aux = head_;
head_ = head_->get_next();
delete aux;
aux = NULL;
}
sz_ = 0;
head_ = NULL;
tail_ = NULL;
}
los errores que me da el método swap son estos:
In member function 'void AED::dll_t<T>::swap(int, int)':
64 37 [Error] there are no arguments to 'get_data' that depend on a template parameter, so a declaration of 'get_data' must be available [-fpermissive]
64 37 (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
65 37 [Error] there are no arguments to 'get_data' that depend on a template parameter, so a declaration of 'get_data' must be available [-fpermissive]
86 10 [Error] prototype for 'void AED::dll_t<int>::dll_union(AED::dll_t<int>&, AED::dll_t<int>&, AED::dll_t<int>&)' does not match any in class 'AED::dll_t<int>'
40 8 [Error] candidate is: void AED::dll_t<T>::dll_union(AED::dll_t<int>&, AED::dll_t<int>&, AED::dll_t<int>&) [with T = int]
Este es el método get_data();
template <class T>
T dll_node_t<T>::get_data(void) const
{
return data_;
}
Gracias
main.cpp
?get_data
?