Programacion En C++

Páginas: 7 (1748 palabras) Publicado: 24 de julio de 2012
Nodo.h #ifndef NODO_H #define NODO_H #include <iostream> using namespace std; template <class T> class Nodo { public: T dato; Nodo *sgte; Nodo(); Nodo(T);~Nodo(); void print(); void eliminar(); }; #endif // NODO_H |
Nodo.cpp #include "Nodo.h"//constructor por defectotemplate<typename T>Nodo<T>::Nodo(){ dato = NULL; sgte = NULL;}//constructor por parametrotemplate<typenameT>Nodo<T>::Nodo(T dato_){ dato = dato_; sgte = NULL;}//imprimir un nodotemplate<typename T>void Nodo<T>::print(){ //cout << "Nodo-> " << "Dato: " << dato << " Direcion: " << this << " Siguiente: " << sgte << endl; cout << dato << "-> ";}//eliminar todos los nodostemplate<typename T>voidNodo<T>::eliminar(){ if(sgte) sgte->eliminar(); delete this;}template<typename T>Nodo<T>::~Nodo(){} |
Lista.h #ifndef LISTA_H#define LISTA_H#include <iostream>#include "time.h"#include <fstream>#include <string>#include "Nodo.h"#include "Nodo.cpp"using namespace std;template <class T>class Lista{ private:int dim,num_nodos; T line; string archivo; public: T ele; Nodo<T> *head; Lista(); ~Lista(); void llenar_teclado(int); void llenar_aleatorio(int); void print(); void add_end(T); void add_head(T); void add_sort(T); void search(T); void del_dato(T); void del_pos(int); void del_all(); void invertir(); void sort(); void load(string);void save(string); void concat(Lista); void interseccion(Lista);};#endif // LISTA_H |
Lista.cpp #include "Lista.h"using namespace std;//constructor por defectotemplate<typename T>Lista<T>::Lista(){ num_nodos = 0; head = NULL;}//llenar la lista por tecladotemplate<typename T>voidLista<T>::llenar_teclado(int dim){ for(int i=0;i<dim;i++){ cout << "Ingresa el elemento " << i + 1 << endl; cin >> ele; add_end(ele); }}//llenar la lista aleatoriamente para enterostemplate<typename T>void Lista<T>::llenar_aleatorio(int dim){ srand(time(NULL)); for(int i=0;i<dim;i++){ add_end(rand() % 100); }}//imprimir la listatemplate<typename T>voidLista<T>::print(){ Nodo<T> *temp = head; if(!head){ cout << "La lista esta vacia " << endl; } else{ while(temp){ temp->print(); if(!temp->sgte) cout << "NULL"; temp = temp->sgte; } } cout << endl << endl;}//insertar al finaltemplate<typename T>void Lista<T>::add_end(T dato_){ Nodo<T> *temp = head;Nodo<T> *nuevo = new Nodo<T> (dato_); if(!head){ head = nuevo; } else{ while(temp->sgte !=NULL){ temp = temp->sgte; } temp->sgte = nuevo; } num_nodos++;}//insertar al iniciotemplate<typename T>void Lista<T>::add_head(T dato_){ Nodo<T> *temp = head; Nodo<T> *nuevo = new Nodo<T> (dato_); if(!head){ head = nuevo; } else{nuevo->sgte = head; head = nuevo; while(temp){ temp = temp->sgte; } } num_nodos++;}//insertar de manera ordenadatemplate<typename T>void Lista<T>::add_sort(T dato_){ Nodo<T> *nuevo = new Nodo<T> (dato_); Nodo<T> *temp = head; if(!head){ head = nuevo; } else{ if(head->dato > dato_){ nuevo->sgte = head; head = nuevo;...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • programacion C
  • Programacion c++
  • c# Programacion
  • Programacion En C#
  • Programacion en c
  • Programacion en c
  • Programacion en c++
  • Programacion c ++

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS