LISTA.cpp
Código
#include <iostream> #include "Lista.h" Lista::Lista( U_int i ) : TAM( i ), cnt( 0 ) { lista_Ptr = new TIPO_ELEMENTO [i]; } Lista::~Lista() { delete [] lista_Ptr; } void Lista::Borrar( U_int pos ) { if( cnt == 0 ) { std::cerr << "LISTA VACIA"; return; } if( pos < 0 || pos >= cnt) { std::cerr << "Posicion ilegal para borrar"; return; } for( U_int i = pos; i < cnt - 2; i++ ) lista_Ptr[i] = lista_Ptr[i + 1]; cnt--; } void Lista::Insertar( TIPO_ELEMENTO e, U_int pos ) { if( cnt == TAM ) { std::cerr << "LISTA VACIA"; return; } if( pos < 0 || pos > cnt ) { std::cerr << "Posicion ilegal para insertar"; return; } for( U_int i = cnt; i > pos; i-- ) lista_Ptr[i] = lista_Ptr[i-1]; lista_Ptr[pos] = e; cnt++; } bool Lista::Vacia() { return cnt == 0; } void Lista::Mostrar( ostream & sal) const { for( U_int i = 0; i < cnt; i++ ) sal << "Elemento[" << i + 1 << "]:" << lista_Ptr[i] << ","; } ostream &operator<<( ostream & salida, const Lista & L ) { L.Mostrar( salida ); return salida; } TIPO_ELEMENTO Lista::getTAM() const { return TAM; }
Lista.h
Código
#ifndef LISTA_H #define LISTA_H #include <iostream> using std::ostream; using std::istream; typedef int TIPO_ELEMENTO; typedef unsigned int U_int; class Lista{ public: Lista( U_int = 0 ); // Constructor de la clase lista ~Lista(); void Mostrar( ostream &) const; // Muestra lista void Insertar( TIPO_ELEMENTO, U_int ); // Inserta un elemento en la lista en la posicion 'x' void Borrar( U_int ); // Borra un elemento en la lista en la posicion 'x' //void Ordenar(); // Ordena la lista en orden ascendente bool Vacia(); // La lista esta vacia? TIPO_ELEMENTO getTAM() const; friend ostream &operator<<( ostream &, const Lista & ); //friend istream &operator>>( istream &, Lista & ); private: U_int cnt; // Cantidad total de elementos U_int TAM; TIPO_ELEMENTO *lista_Ptr; // Puntero a lista }; #endif
Y el main.cpp
Código
#include <iostream> #include "Lista.h" int main() { U_int tam = 10; Lista L2( tam ); if( L2.Vacia() ) std::cout << "Lista Vacia" << std::endl; else std::cout << "Lista con:" << L2.getTAM() << " elementos" << std::endl; for( U_int i = 0; i < L2.getTAM(); i++ ) L2.Insertar( i*i, i); std::cout << L2; return 0; }
Cuando quiero compilar con F8, me saltan errores:
http://img832.imageshack.us/i/75593839.png/
A qué se debe?
Lo único que supongo es que tal vez no está tomando la implementación... Pero tampoco sé cómo configurarlo para que la tome...