Paste
Copy
Cut
Options

¡Tu solución está lista!

Nuestra ayuda de expertos desglosó tu problema en una solución confiable y fácil de entender.

Mira la respuesta
  • Pregunta: Implementaion (C++) Hash Table Separate Chaining and Open Addressing, for this work use the next code #include <iostream> using namespace std; //TAD template<typename E> class Lista { public: //clear virtual void limpiar() = 0; //Insert virtual void insertar(E elemento) = 0; //add to final virtual void agregar(E elemento) = 0;

    Implementaion (C++) Hash Table Separate Chaining and Open Addressing, for this work use the next code

    #include <iostream>

    using namespace std;

    //TAD
    template<typename E> class Lista
    {
    public:
    //clear
    virtual void limpiar() = 0;
    //Insert
    virtual void insertar(E elemento) = 0;
    //add to final
    virtual void agregar(E elemento) = 0;
    //eraser
    virtual E eliminar() = 0;
    //move to start
    virtual void moverAlInicio() = 0;
    //move to end
    virtual void moverAlFinal() = 0;
    //move to before
    virtual void anterior() = 0;
    //Move to next
    virtual void siguiente() = 0;
    //actual position
    virtual int posicionActual() = 0;
    //actal to pos
    virtual void moverAPosicion(int pos) = 0;
    //length
    virtual int longitud() = 0;
    //return valor
    virtual E getvalor() = 0;
    //
    virtual void setvalor(E elemento) = 0;
    };

    template<typename E> class ListaArreglo: public Lista<E>
    {
    private:
    E* arreglo;
    int tamMax;
    int tamLista;
    int actual;

    public:
    ListaArreglo(int tamMax=100)
    {
    this->tamMax = tamMax;
    this->tamLista = this->actual = 0;
    this->arreglo = new E[this->tamMax];
    }
    ~ListaArreglo()
    {
    delete[] this->arreglo;
    }
    void moverAlInicio()
    {
    this->actual = 0;
    }
    void moverAlFinal()
    {
    this->actual = tamLista-1;
    }
    void siguiente()
    {
    if(this->actual < this->tamLista)
    {
    this->actual++;
    }
    }
    void anterior()
    {
    if(this->actual >= 0)
    {
    this->actual--;
    }
    }
    void agregar(E elemento)
    {
    if(this->tamLista < this->tamMax)
    {
    this->arreglo[this->tamLista++] = elemento;
    }
    }
    int longitud()
    {
    return this->tamLista;
    }
    int posicionActual()
    {
    return this->actual;
    }
    void moverAPosicion(int pos)
    {
    if(pos>=0 && pos<this->tamLista)
    {
    this->actual = pos;
    }
    }
    E getvalor()
    {
    return this->arreglo[this->actual];
    }
    void setvalor(E elemento)
    {
    this->arreglo[this->actual] = elemento;
    }
    void limpiar()
    {
    delete[] this->arreglo;
    this->tamLista = this->actual = 0;
    this->arreglo = new E[this->tamMax];
    }
    void insertar(E elemento)
    {
    for(int i=this->tamLista; i>this->actual;i--)
    {
    this->arreglo[i] = this->arreglo[i-1];
    }
    this->arreglo[this->actual] = elemento;
    this->tamLista++;
    }

    E eliminar()
    {
    E eliminado = this->arreglo[this->actual];
    for (int i = this->actual; i < this->tamLista; ++i)
    {
    this->arreglo[i] = this->arreglo[i + 1];
    }
    this->tamLista--;
    return eliminado;
    }
    };


    //Node linked list
    template<typename E> class Nodo{
    public:
    E elemento;
    Nodo *siguiente;

    Nodo(E elem, Nodo* proximo = NULL){
    this->elemento = elem;
    this->siguiente = proximo;
    }

    Nodo(Nodo* proximo = NULL){
    this->siguiente = proximo;
    }
    };


    template<typename E> class ListaEnlazada: public Lista<E>
    {
    private:
    Nodo<E> *cabeza;
    Nodo<E> *actual;
    Nodo<E> *cola;
    int cantidad;
    public:
    void inicializar(){
    this->cantidad = 0;
    this->cola = this->actual = this->cabeza = new Nodo<E>;
    }

    ListaEnlazada(){
    inicializar();
    }

    ~ListaEnlazada(){
    while (this->cabeza != NULL)
    {
    this->actual = this->cabeza;
    this->cabeza = this->cabeza->siguiente;
    delete actual;
    }
    }

    void limpiar() {
    while (this->cabeza != NULL)
    {
    this->actual = this->cabeza;
    this->cabeza = this->cabeza->siguiente;
    delete actual;
    }
    inicializar();
    }

    void agregar(E elemento) {
    this->cola->siguiente = new Nodo<E>(elemento, NULL);
    this->cola = this->cola->siguiente;
    this->cantidad++;
    }

    void insertar(E elemento) {
    if ( this->actual->siguiente == this->cola ) {
    this->cola->siguiente = new Nodo<E>(elemento, NULL);
    this->cola = this->cola->siguiente;
    } else {
    Nodo<E> *temp = new Nodo<E>(elemento, this->actual->siguiente);
    this->actual->siguiente = temp;
    };
    this->cantidad++;
    }

    void moverAlInicio() {
    this->actual = this->cabeza;
    }

    E eliminar() {
    Nodo<E> *temp = this->actual->siguiente;
    if ( this->actual->siguiente == this->cola ) {
    this->actual->siguiente = NULL;
    this->cola = this->actual;
    } else {
    this->actual->siguiente = this->actual->siguiente->siguiente;
    }
    this->cantidad--;
    return temp->elemento;
    }

    void moverAlFinal() {
    this->actual = this->cabeza;
    for ( int i = 1; i< this->cantidad; ++i) {
    this->actual = this->actual->siguiente;
    }
    }

    void siguiente() {
    if(this->actual != this->cola) {
    this->actual = this->actual->siguiente;
    }
    }

    void anterior() {
    Nodo<E> *temp = this->actual;
    this->actual = this->cabeza;
    if ( temp != this->cabeza ) {
    for( int i=0; temp != this->actual->siguiente; ++i) {
    this->actual = this->actual->siguiente;
    }
    }
    }

    int posicionActual() {
    Nodo<E> *temp = this->cabeza;
    int i;
    for ( i=1; temp != this->actual; ++i)
    temp = temp->siguiente;
    return i;
    }

    void moverAPosicion(int pos) {
    if ( pos-1 < this->cantidad ) {
    this->actual = this->cabeza;
    for (int i=0; i < pos-1; ++i) {
    this->actual = this->actual->siguiente;
    }
    } else {
    cout<<"Mover a posicion invalido"<<endl;
    }
    }

    int longitud() {
    return this->cantidad;
    }

    E getvalor() {
    return this->actual->siguiente->elemento;
    }

    void setvalor(E elemento) {
    this->actual->siguiente->elemento = elemento;
    }
    };

    int main(){


    return 0;
    }


  • Chegg Logo
    Esta es la mejor manera de resolver el problema.
    Solución

    Program screenshots: Sample output: Code to be copied: Hashtable.cpp   //Include header files #include <iostream> #include <list> using namespace std;   //Create hashtable class class HashTable {   //Declare memeber variables private: //Declare lis

    Mira la respuesta completa
    answer image blur