AYUIDA URGENTE DE ESTO DEPENDE APROBAR LA ASIGNATURA
Definir una estructiura de datos para implementar una lista que contiene dos datos: un numero ID y otro canpo que es una caracter LE.Queremos ademas q cada elemento de cada lista disponga de un enlance al siguiente elemento de la lista que le corresponde segun un orden numerico ascendente de ID, por otra parte debera poseerotro campo qeu enlazara con el siguiente elemento de la lista segun un orden alzabetico del campo LE
2. modulo que dado un codigo numerico ya leido devuelva el caracter asociado, si dicho codigo existia en la lista y error en caso contrario.
3.modulo que dado un ID numerico y caracter ambos ya leidos intercale un nuevo nodo en el lugar correspondiente de ambas listas o devuleva error si al menos una clave ya existia en la lista
4.modulo que dado un numero entero devuleva la posicion que ocupa en la lista de enteros.
5. idem a la anterior pero para el campo LE
6.modulo que borre un elemento d ela lista identificandolo por el ID
2. modulo que dado un codigo numerico ya leido devuelva el caracter asociado, si dicho codigo existia en la lista y error en caso contrario.
3.modulo que dado un ID numerico y caracter ambos ya leidos intercale un nuevo nodo en el lugar correspondiente de ambas listas o devuleva error si al menos una clave ya existia en la lista
4.modulo que dado un numero entero devuleva la posicion que ocupa en la lista de enteros.
5. idem a la anterior pero para el campo LE
6.modulo que borre un elemento d ela lista identificandolo por el ID
Te mando un header file generico para listas enlazadas, que contiene las funciones que tu necesitas para implementar el programa.
Tienes que cambiar la estructura Node, de acuerdo a tus necesidades, y escribir el correspondiente programa cpp.
Exito ! ! !
// program LinkList.h - page 366 . . . . .
// Header File for Linked List.
// c++ exercices book - dr. gershon kagan - first edition : 2001
// written in Borland CPP ver 3.1
#include <conio.h>
#include <iostream.h>
#include <iomanip.h>
template <class T>
struct Node
{
T info;
Node<T> *next;
}; // STRUCT NODE
template <class T>
class LinkedList
{
private:
Node<T> *begin;
int len;
public:
LinkedList(int num = 0,T *data = NULL);
LinkedList(LinkedList &right);
~LinkedList();
int GetLen() {return len;}; // GET LEN
Node<T> *GetBegin() {return begin;} // GET BEGIN
void SetBegin(Node<T> *BEGIN) {begin = BEGIN;} // SET BEGIN
T operator [] (int index) const;
void FirstDelete(Node<T> *actual);
void InnerDelete(Node<T> *anterior);
void Remove(Node<T> *p);
void FirstInsert(Node<T> *pMin);
void Insert(Node<T> *p,Node<T> *pMin);
friend ostream &operator<<(ostream &,const LinkedList &);
}; // CLASS LINKED LIST
template <class T>
LinkedList<T>::LinkedList(int num = 0,T *data = NULL)
{
if(!data)
{
begin = NULL;
len = 0;
}
else
{
len = 1;
begin = new Node<T>;
Node<T> *p = begin;
p->info = data[0];
for(int i = 1;i < num;i++)
{
p->next = new Node<T>;
p = p->next;
p->info = data[i];
len++;
}
p->next = NULL;
}
} // LINKED LIST CONSTRUCTOR
template <class T>
LinkedList<T>::LinkedList(LinkedList<T> &right)
{
Node<T> *p = right.GetBegin(),*q;
if(!p)
{
begin = NULL;
}
else
{
this->begin = new Node<T>;
q = this->begin;
q->info = p->info;
p = p->next;
while(p)
{
q->next = new Node<T>;
q = q->next;
q->info = p->info;
p = p->next;
}
q->next = NULL;
len = right.len;
}
} // LINKED LIST COPY CONSTRUCTOR
template <class T>
LinkedList<T>::~LinkedList()
{
Node<T> *p = begin,*q;
while(p)
{
q = p;
p = p->next;
delete q;
}
} // LINKED LIST DESTRUCTOR
template <class T>
T LinkedList<T>::operator [] (int index) const
{
if(index < 0 || index >= len)
{
cout << index << " out of range index ";
return 0;
}
Node<T> *p = begin;
while(index)
{
index--;
p = p->next;
}
return p->info;
} // LINKED LIST OPERATOT []
template <class T>
void LinkedList<T>::FirstDelete(Node<T> *actual) // remode and delete node
{ // at the begining of list
cout << setw(30) << "first delete . . . . " << actual->info << endl;
begin = actual->next;
delete actual;
len--;
} // LINKED LIST FIRST DELETE
template <class T>
void LinkedList<T>::InnerDelete(Node<T> *anterior) // remode and delete node
{ // inside the list
Node<T> *actual = anterior->next;
cout << setw(30) << "delete . . . . " << actual->info << endl;
anterior->next = actual->next;
anterior->next = actual->next; // ***************
delete actual;
len--;
} // LINKED LIST INNER DELETE
template <class T>
void LinkedList<T>::Remove(Node<T> *p) // remove node inside the list
{ // without destruyed it
p->next = p->next->next;
} // REMOVE
template <class T>
void LinkedList<T>::FirstInsert(Node<T> *pMin) // insert existent node
{ // at the begining of list
pMin->next = begin;
begin = pMin;
} // FIRST INSERT
template <class T>
void LinkedList<T>::Insert(Node<T> *p,Node<T> *pMin) // insert existent node
{ // inside the list
pMin->next = p->next;
pMin->next = p->next;
p->next = pMin;
p->next = pMin;
} // INSERT
template <class T>
ostream &operator<<(ostream &out,const LinkedList <T> &LIST)
{
Node<T> *p = LIST.begin;
if(!p)
out << "{empty list}";
else
{
out << "{" << p->info;
p = p->next;
for(;p;p = p->next)
out << "," << p->info;
}
out << "}" << endl;
return out;
} // OPERATOR <<
Tienes que cambiar la estructura Node, de acuerdo a tus necesidades, y escribir el correspondiente programa cpp.
Exito ! ! !
// program LinkList.h - page 366 . . . . .
// Header File for Linked List.
// c++ exercices book - dr. gershon kagan - first edition : 2001
// written in Borland CPP ver 3.1
#include <conio.h>
#include <iostream.h>
#include <iomanip.h>
template <class T>
struct Node
{
T info;
Node<T> *next;
}; // STRUCT NODE
template <class T>
class LinkedList
{
private:
Node<T> *begin;
int len;
public:
LinkedList(int num = 0,T *data = NULL);
LinkedList(LinkedList &right);
~LinkedList();
int GetLen() {return len;}; // GET LEN
Node<T> *GetBegin() {return begin;} // GET BEGIN
void SetBegin(Node<T> *BEGIN) {begin = BEGIN;} // SET BEGIN
T operator [] (int index) const;
void FirstDelete(Node<T> *actual);
void InnerDelete(Node<T> *anterior);
void Remove(Node<T> *p);
void FirstInsert(Node<T> *pMin);
void Insert(Node<T> *p,Node<T> *pMin);
friend ostream &operator<<(ostream &,const LinkedList &);
}; // CLASS LINKED LIST
template <class T>
LinkedList<T>::LinkedList(int num = 0,T *data = NULL)
{
if(!data)
{
begin = NULL;
len = 0;
}
else
{
len = 1;
begin = new Node<T>;
Node<T> *p = begin;
p->info = data[0];
for(int i = 1;i < num;i++)
{
p->next = new Node<T>;
p = p->next;
p->info = data[i];
len++;
}
p->next = NULL;
}
} // LINKED LIST CONSTRUCTOR
template <class T>
LinkedList<T>::LinkedList(LinkedList<T> &right)
{
Node<T> *p = right.GetBegin(),*q;
if(!p)
{
begin = NULL;
}
else
{
this->begin = new Node<T>;
q = this->begin;
q->info = p->info;
p = p->next;
while(p)
{
q->next = new Node<T>;
q = q->next;
q->info = p->info;
p = p->next;
}
q->next = NULL;
len = right.len;
}
} // LINKED LIST COPY CONSTRUCTOR
template <class T>
LinkedList<T>::~LinkedList()
{
Node<T> *p = begin,*q;
while(p)
{
q = p;
p = p->next;
delete q;
}
} // LINKED LIST DESTRUCTOR
template <class T>
T LinkedList<T>::operator [] (int index) const
{
if(index < 0 || index >= len)
{
cout << index << " out of range index ";
return 0;
}
Node<T> *p = begin;
while(index)
{
index--;
p = p->next;
}
return p->info;
} // LINKED LIST OPERATOT []
template <class T>
void LinkedList<T>::FirstDelete(Node<T> *actual) // remode and delete node
{ // at the begining of list
cout << setw(30) << "first delete . . . . " << actual->info << endl;
begin = actual->next;
delete actual;
len--;
} // LINKED LIST FIRST DELETE
template <class T>
void LinkedList<T>::InnerDelete(Node<T> *anterior) // remode and delete node
{ // inside the list
Node<T> *actual = anterior->next;
cout << setw(30) << "delete . . . . " << actual->info << endl;
anterior->next = actual->next;
anterior->next = actual->next; // ***************
delete actual;
len--;
} // LINKED LIST INNER DELETE
template <class T>
void LinkedList<T>::Remove(Node<T> *p) // remove node inside the list
{ // without destruyed it
p->next = p->next->next;
} // REMOVE
template <class T>
void LinkedList<T>::FirstInsert(Node<T> *pMin) // insert existent node
{ // at the begining of list
pMin->next = begin;
begin = pMin;
} // FIRST INSERT
template <class T>
void LinkedList<T>::Insert(Node<T> *p,Node<T> *pMin) // insert existent node
{ // inside the list
pMin->next = p->next;
pMin->next = p->next;
p->next = pMin;
p->next = pMin;
} // INSERT
template <class T>
ostream &operator<<(ostream &out,const LinkedList <T> &LIST)
{
Node<T> *p = LIST.begin;
if(!p)
out << "{empty list}";
else
{
out << "{" << p->info;
p = p->next;
for(;p;p = p->next)
out << "," << p->info;
}
out << "}" << endl;
return out;
} // OPERATOR <<
