Está en la página 1de 29

2018

UNIVERSIDAD NACIONAL
“PEDRO RUÍZ GALLO”
FACFYM
ESCUELA PROFESIONAL DE INGENIERÍA EN
COMPUTACIÓN E INFORMÁTICA
“AÑO DE LA CONSOLIDACIÓN DEL MAR DE GRAU”

ASIGNATURA

ALGORITMOS Y ESTRUCTURA DE DATOS II

TEMA
Lista Enlazada Circular Simple

PROFESOR

Carlos Valdivia Salazar

INTEGRANTES

 ARROYO BARRANZUELA, Karina M.


 FACUNDO BARBOZA, Fiorella M.
 RAMOS BENITES, Richard A.
 SANTISTEBAN PISFIL, Leidy D.

Lambayeque, febrero de 2018


3

INTRODUCCIÓN

Este trabajo se presenta con el objetivo de desarrollar el tema de Listas


Circulares Simples, así como el desarrollo de un ejercicio.

A diferencia de las listas anteriormente estudiadas, este tipo de listas


tiene una característica adicional y es que no tiene fin, por eso mismo
nos permite acceder directamente a cualquiera de sus elementos que le
proceden.

A continuación desarrollaremos el tema tomando como ejemplo un


sistema de farmacia.

3
4

MARCO TEÓRICO

La lista circular simple nos permite a partir de un elemento acceder


directamente a cualquiera de los elementos que le preceden. En lugar de
almacenar un puntero NULO en el campo SGTE del último elemento de la lista,
se hace que el último elemento apunte al primero o principio de la lista. Este
tipo de estructura también se le denomina listas en anillo.

Cab

¿Por qué utilizar una estructura Circular?

En una lista simplemente enlazada, el movimiento siempre fluirá desde la


cabeza en dirección hacia el final de la lista, pero ¿qué ocurre cuando desde el
último nodo se necesita operar con el primero?, este es el punto diferencial de
una estructura abierta y una cerrada.

Ventajas:

• Cada nodo de una lista circular es accesible desde cualquier otro nodo de
ella. Es decir, dado un nodo se puede recorrer toda la lista completa.

• Las operaciones de concatenación y división de listas son más eficaces


con listas circulares.

Desventajas:

• Se pueden producir lazos o bucles infinitos. Una forma de evitar estos


bucles infinitos es disponer de un nodo especial que se encuentre
permanentemente asociado a la existencia de la lista circular. Este nodo se
denomina cabecera de la lista.

4
5

ESTRUCTURAS UTILIZADAS:

Normalmente los tipos que se definen en las listas cerradas son las mismas
que las listas abiertas. Siendo el Nodo aquel que contiene la información que
va a ser guardada y al nodo puntero siguiente, el cual permitirá el avance de un
nodo a otro. Finalmente se crea una Lista la cual tiene a un total y a la
cabecera que contiene la información del nodo.

5
6

struct Producto{ struct Vendedor{


char codigo[10]; char DNI[10];
char descripción[20]; char nombre[20];
int stock; char telefono[10];
float precio; char direccion[20];
}; };

struct NodoProducto{ struct NodoVendedor{


Producto info; Vendedor info;
NodoProducto *sgte; NodoVendedor *sgte;
}; };

struct ListaProducto{ struct ListaVendedor{


int total; int total;
NodoProducto *cab; NodoVendedor *cab;
}; };

struct ProductoFactura{ struct Factura{


char codProducto[10]; char DNIVendedor[10];
int cantidad; char numFactura[10];
float subtotal; char DNICliente[10];
}; char nombre[20];
float montoTotal;
struct NodoProductoFactura{ ListaProductoFactura LPF;
ProductoFactura info; };
NodoProductoFactura *sgte;
}; struct NodoFactura{
Factura info;
struct ListaProductoFactura{ NodoFactura *sgte;
int total; };
NodoProductoFactura *cab;
}; struct ListaFactura{
int total;
NodoFactura *cab;
};

6
7

OPERACIONES:
Para todas las estructuras hemos implementado las siguientes operaciones
básicas:

 INSERTAR

 Inserta al Inicio

void InsertarInicio(ListaProducto &LP,


Producto P){
NodoProducto* aux = new NodoProducto;

aux->info = P;
aux->sgte = NULL;
if(LP.cab==NULL){
LP.cab=aux;
aux->sgte = aux;

}else{
NodoProducto *temp;

temp=LP.cab;
while(temp->sgte!=LP.cab){
temp = temp->sgte;
}

temp->sgte = aux;
aux->sgte = LP.cab;
LP.cab=aux;

}
LP.total++;
}

7
8

 Inserta al Final

void InsertarFinal(ListaProducto &LP, Producto P){


NodoProducto *aux = new NodoProducto;

aux->info = P;
aux->sgte = NULL;

if(LP.cab == NULL){
LP.cab = aux;
aux->sgte=aux;
}else{
NodoProducto *temp;
temp = LP.cab;

while(temp->sgte != LP.cab){
temp = temp->sgte;
}
temp->sgte = aux;
aux->sgte=LP.cab;
}
LP.total ++;
}

temp

total aux
info info

cab sgte
sgte info

sgte

8
9

 Inserta en Posición

void InsertarPosicion(ListaProducto &LP, Producto P,


NodoProducto *pos){

if(pos == LP.cab){
InsertarInicio(LP, P);
}
else{

if(pos->sgte == LP.cab){
InsertarFinal(LP, P);
}
else{

NodoProducto *aux = new NodoProducto;


NodoProducto *a_Pos;

a_Pos=LP.cab;
while(a_Pos->sgte!=pos){
a_Pos=a_Pos->sgte;
}
aux->info = P;

aux->sgte = pos;
a_Pos->sgte=aux;
LP.total++;
}
}
}

a_Pos

total
info info

cab sgte sgte

info
pos
sgte
aux
9
10

 ELIMINAR

 Elimina al Inicio

void EliminaInicio(ListaProducto &LP){


NodoProducto *temp;
temp=LP.cab;

if(LP.total > 0){


NodoProducto *aux;
aux = LP.cab;
while(aux->sgte != LP.cab){
aux = aux->sgte;
}
aux->sgte = LP.cab->sgte;
LP.cab = temp->sgte;
delete temp;
LP.total--;
cout << "\n\t Producto eliminado\n" << endl;
}else
cout << "\n\t Lista Vacia\n" << endl;

system("pause");
}

 Elimina al Final

void EliminaFinal(ListaProducto &LP){


NodoProducto *temp = LP.cab;
NodoProducto *aux= LP.cab;

if(LP.total > 0){


while(temp->sgte != LP.cab)
temp = temp->sgte;
while(aux->sgte != temp)
aux = aux->sgte;
aux->sgte=LP.cab;

delete temp;
LP.total--;

cout << "\n\t Producto Eliminado\n" << endl;


}else
cout << "\n\t Lista Vacia\n" << endl;
system("pause");
}

10
11

 Elimina en Posición

void EliminaPosicion(ListaProducto &LP, NodoProducto *pos){

NodoProducto *aux;

if(pos==LP.cab){
EliminaInicio(LP);
}else
if(pos->sgte==LP.cab)
EliminaFinal(LP);
else{
aux=LP.cab;
while(aux->sgte!=pos){
aux=aux->sgte;
}
aux->sgte=pos->sgte;
delete pos;
LP.total--;
}
}

11
12

 PRESENTAR

void Presenta(ListaProducto LP){


NodoProducto *aux;
int i=1;
if(LP.cab==NULL){
cout << "\n\tLista Vacia. \n"<< endl;
}else{
int band=0;
aux=LP.cab;
while(band==0){
cout<<"\n\t---------------------------------"<<endl;
cout << "\tPRODUCTO NRO: "<<i<<endl;
i++;
cout<<"\t---------------------------------"<<endl;
Mostrar(aux->info);
cout<<"\t---------------------------------"<<endl;
if(aux->sgte==LP.cab){
band=1;
}
aux=aux->sgte;
}

}
system("pause");
}

 BUSCAR
void opBuscar(ListaProducto LP){
char cod[10];

NodoProducto *Pos;
cout<<"\n\tIngrese codigo del producto a buscar: ",cin>>
cod;

Pos=Buscar(LP,cod);

if (Pos !=NULL) {
Mostrar(Pos->info);
}
else {
cout <<"\n\tCodigo no Existe..\n"<<endl;
}
system("pause");
}

12
13

NodoProducto *Buscar(ListaProducto &LP, char cod[]){


NodoProducto *aux;

int band=0;
aux=LP.cab;
while(band==0){
if(strcmp(aux->info.codigo, cod) == 0){
return aux;
}
if(aux->sgte==LP.cab){
band=1;
}
aux=aux->sgte;
}
return NULL;
}

UTILIDADES DE LA LISTA:
Cada lista contiene al nodo cabecera (CAB), este a su vez los datos
pertenecientes a su estructura conocido también como INFO y al mismo tiempo
tiene un puntero siguiente (SGTE) de tipo nodo que es aquel que relaciona los
nodos o elementos.

13
14

EJEMPLO DESARROLLADO:
#include <iostream> //---------
#include <string.h>
using namespace std; struct Factura{
char DNIVendedor[10];
//********************************* char numFactura[10];
************* REGISTROS *********** char DNICliente[10];
//--------- char nombre[20];
struct Producto{ float montoTotal;
char codigo[10]; ListaProductoFactura LPF;
char descripcion[20]; };
int stock;
float precio; struct NodoFactura{
}; Factura info;
NodoFactura *sgte;
struct NodoProducto{ };
Producto info;
NodoProducto *sgte; struct ListaFactura{
}; int total;
NodoFactura *cab;
struct ListaProducto{ };
int total;
NodoProducto *cab; //---------
};
//--------- //*********************************
struct Vendedor{ ****** PRODUCTO ******************
char DNI[10];
char nombre[20]; //FUNCIONES BASICAS PRODUCTO ------
char telefono[10]; -------------
char direccion[20];
}; void Llenar(Producto &P){
cout <<"\n\t (*) Codigo: "; cin
struct NodoVendedor{ >> P.codigo;
Vendedor info; printf("\t (*) Descripcion: ");
NodoVendedor *sgte; fflush(stdin);
}; gets(P.descripcion);
cout <<"\t (*) Stock: "; cin >>
struct ListaVendedor{ P.stock;
int total; cout <<"\t (*) Precio: "; cin
NodoVendedor *cab; >> P.precio;
}; }
//---------
void Mostrar(Producto P){
struct ProductoFactura{ cout<<"\t (*) Codigo:
char codProducto[10]; "<<P.codigo<<endl;
int cantidad; cout<<"\t (*) Descripcion:
float subtotal; "<<P.descripcion<<endl;
}; cout<<"\t (*) Stock:
"<<P.stock<<endl;
struct NodoProductoFactura{ cout<<"\t (*) Precio:
ProductoFactura info; "<<P.precio<<endl;
NodoProductoFactura *sgte; }
};
//OPERACIONES DE LISTA PRODUCTO ---
struct ListaProductoFactura{
int total; void Inicializa(ListaProducto &LP){
NodoProductoFactura *cab; LP.total = 0;
}; LP.cab = NULL;
}
14
15

else{
void InsertarInicio(ListaProducto
&LP, Producto P){ if(pos->sgte == LP.cab){
NodoProducto* aux = new InsertarFinal(LP, P);
NodoProducto; }
else{
NodoProducto *aux = new
aux->info = P; NodoProducto;
aux->sgte = NULL; NodoProducto *a_Pos;
if(LP.cab==NULL){
LP.cab=aux; aux->info = P;
aux->sgte = aux; aux->sgte = NULL;
a_Pos=LP.cab;
}else{ while(a_Pos->sgte!=pos){
NodoProducto* temp; a_Pos=a_Pos->sgte;
}
temp = LP.cab; aux->sgte = pos;
while(temp->sgte!=LP.cab){ a_Pos->sgte=aux;
temp = temp->sgte; LP.total++;
} }
}
temp->sgte = aux; }
aux->sgte = LP.cab;
LP.cab=aux; void EliminaInicio(ListaProducto
&LP){
} NodoProducto *temp;
LP.total++; temp = LP.cab;
}
if(LP.total > 0){
void InsertarFinal(ListaProducto NodoProducto *aux;
&LP, Producto P){ aux=LP.cab;
NodoProducto *aux = new while(aux->sgte!=LP.cab){
NodoProducto; aux=aux->sgte;
NodoProducto *temp; }
aux->sgte=LP.cab->sgte;
aux->info = P; LP.cab=temp->sgte;
aux->sgte = NULL; delete temp;
LP.total--;
cout << "\n\t Producto
if(LP.cab == NULL){ eliminado\n" << endl;
LP.cab = aux; }else
aux->sgte=aux; cout << "\n\t Lista
}else{ Vacia\n" << endl;
temp = LP.cab;
system("pause");
while(temp->sgte != LP.cab){ }
temp = temp->sgte;
} void EliminaFinal(ListaProducto
temp->sgte = aux; &LP){
aux->sgte=LP.cab; NodoProducto *temp = LP.cab;
} NodoProducto *aux= LP.cab;
LP.total ++;
} if(LP.total > 0){
while(temp->sgte != LP.cab)
void InsertarPosicion(ListaProducto temp = temp->sgte;
&LP, Producto P, NodoProducto while(aux->sgte != temp)
*pos){ aux = aux->sgte;
aux->sgte=LP.cab;
if(pos == LP.cab){
InsertarInicio(LP, P); delete temp;
} LP.total--;
15
16

NodoProducto *Buscar(ListaProducto
cout << "\n\t Producto &LP, char cod[]){
Eliminado\n" << endl; NodoProducto *aux;
}else
cout << "\n\t Lista int band=0;
Vacia\n" << endl; aux=LP.cab;
system("pause"); while(band==0){
} if(strcmp(aux->info.codigo,
cod) == 0){
void EliminaPosicion(ListaProducto return aux;
&LP, NodoProducto *pos){ }
if(aux->sgte==LP.cab){
NodoProducto *aux; band=1;
}
if(pos==LP.cab){ aux=aux->sgte;
EliminaInicio(LP); }
}else return NULL;
if(pos->sgte==LP.cab) }
EliminaFinal(LP);
else{ //*********************************
aux=LP.cab; ************* VENDEDOR ***********
while(aux->sgte!=pos){
aux=aux->sgte; //FUNCIONES BASICAS VENDEDOR ------
} ------------------
aux->sgte=pos->sgte;
delete pos; void Llenar(Vendedor &V){
LP.total--; cout <<"\n\t (*) DNI: "; cin
} >> V.DNI;
} printf("\t (*) Nombre: ");
fflush(stdin);
void Presenta(ListaProducto LP){ gets(V.nombre);
NodoProducto *aux; cout <<"\t (*) Telefono: ";
int i=1; cin >> V.telefono;
if(LP.cab==NULL){ printf("\t (*) Direccion: ");
cout << "\n\tLista Vacia. fflush(stdin);
\n"<< endl; gets(V.direccion);
}else{ }
int band=0;
aux=LP.cab; void Mostrar(Vendedor V){
while(band==0){ cout<<"\t (*) DNI:
cout<<"\n\t------------ "<<V.DNI<<endl;
---------------------"<<endl; cout<<"\t (*) Nombre:
cout << "\tPRODUCTO "<<V.nombre<<endl;
NRO: "<<i+1<<endl; cout<<"\t (*) Telefono:
cout<<"\t-------------- "<<V.telefono<<endl;
-------------------"<<endl; cout<<"\t (*) Direccion:
Mostrar(aux->info); "<<V.direccion<<endl;
cout<<"\t-------------- }
-------------------"<<endl;
if(aux->sgte==LP.cab){ //OPERACIONES DE LISTA VENDEDOR ---
band=1; -------------------
}
aux=aux->sgte; void Inicializa(ListaVendedor &Lv){
} Lv.total = 0;
Lv.cab = NULL;
} }
system("pause");
} void InsertarInicio(ListaVendedor
&Lv, Vendedor V){
NodoVendedor* aux = new
NodoVendedor;
16
17

InsertarFinal(Lv, V);
}
aux->info = V; else{
aux->sgte = NULL;
if(Lv.cab==NULL){ NodoVendedor *aux = new
Lv.cab=aux; NodoVendedor;
aux->sgte = aux; NodoVendedor *a_Pos;

}else{ aux->info = V;
NodoVendedor* temp; aux->sgte = NULL;
a_Pos=Lv.cab;
temp=Lv.cab; while(a_Pos->sgte!=pos){
while(temp- a_Pos=a_Pos->sgte;
>sgte!=Lv.cab){ }
temp = temp->sgte; aux->sgte = pos;
} a_Pos->sgte=aux;
Lv.total++;
temp->sgte = aux; }
aux->sgte = Lv.cab; }
Lv.cab=aux; }

} void EliminaInicio(ListaVendedor
Lv.total++; &Lv){
} NodoVendedor *temp;
temp=Lv.cab;
void InsertarFinal(ListaVendedor
&Lv, Vendedor V){ if(Lv.total > 0){
NodoVendedor *aux = new NodoVendedor *aux;
NodoVendedor; aux=Lv.cab;
NodoVendedor *temp; while(aux->sgte!=Lv.cab){
aux=aux->sgte;
aux->info = V; }
aux->sgte = NULL; aux->sgte=Lv.cab->sgte;
Lv.cab=temp->sgte;
delete temp;
if(Lv.cab == NULL){ Lv.total--;
Lv.cab = aux; cout << "\n\tVendedor
aux->sgte=aux; eliminado\n" << endl;
}else{ }else
temp = Lv.cab; cout << "\n\tLista Vacia\n"
<< endl;
while(temp->sgte !=
Lv.cab){ system("pause");
temp = temp->sgte; }
}
temp->sgte = aux; void EliminaFinal(ListaVendedor
aux->sgte=Lv.cab; &Lv){
} NodoVendedor *temp = Lv.cab;
Lv.total ++; NodoVendedor *aux= Lv.cab;
}
if(Lv.total > 0){
void InsertarPosicion(ListaVendedor while(temp->sgte != Lv.cab)
&Lv, Vendedor V, NodoVendedor temp = temp->sgte;
*pos){ while(aux->sgte != temp)
aux = aux->sgte;
if(pos == Lv.cab){ aux->sgte=Lv.cab;
InsertarInicio(Lv, V);
} delete temp;
else{ Lv.total--;

if(pos->sgte == Lv.cab){
17
18

cout << "\n\tVendedor NodoVendedor *aux;


eliminado\n" << endl;
}else int band=0;
cout << "\n\tLista Vacia\n" aux=Lv.cab;
<< endl; while(band==0){
system("pause"); if(strcmp(aux->info.DNI,
} DNI) == 0){
return aux;
void EliminaPosicion(ListaVendedor }
&Lv, NodoVendedor *pos){ if(aux->sgte==Lv.cab){
NodoVendedor *aux; band=1;
}
if(pos==Lv.cab){ aux=aux->sgte;
EliminaInicio(Lv); }
}else return NULL;
if(pos->sgte==Lv.cab) }
EliminaFinal(Lv);
else{ //*********************************
aux=Lv.cab; *********** PRODUCTO_FACTURA ******
while(aux->sgte!=pos){
aux=aux->sgte; //FUNCIONES BASICAS
} PRODUCTO_FACTURA
aux->sgte=pos->sgte; void Llenar(ProductoFactura &PF,
delete pos; ListaProducto &LP){
Lv.total--; int band=0;
}
} NodoProducto *pos;
do{
do{
void Presenta(ListaVendedor Lv){ cout <<"\n\t (*) Codigo
NodoVendedor *aux; int i=1; de Producto: "; cin >>
PF.codProducto;
if(Lv.cab==NULL){
cout << "Lista Vacia. "<< pos=Buscar(LP,PF.codProducto);
endl; if(pos!=NULL){
}else{ cout <<"\t (*)
int band=0; Cantidad: "; cin >> PF.cantidad;
aux=Lv.cab; if(pos-
while(band==0){ >info.stock>=PF.cantidad){
cout<<"\n\t------------ pos-
---------------------"<<endl; >info.stock=pos->info.stock-
cout << "\tVENDEDOR PF.cantidad;
NRO: "<<i<<endl;
cout<<"\t-------------- PF.subtotal=PF.cantidad*pos-
-------------------"<<endl; >info.precio;
i++; cout <<
Mostrar(aux->info); "\n\tSe Realizo Venta.\n "<< endl;
cout<<"\t-------------- band=1;
-------------------"<<endl; }else{
if(aux->sgte==Lv.cab){ cout <<
band=1; "\n\tNo hay suficiente
} stock\n"<<endl;
aux=aux->sgte; band=0;
} }
}else
} cout<<"\n\t Codigo
system("pause"); no encntrado.\n" << endl;
} }while(band!=1);
}while(pos==NULL);
NodoVendedor *Buscar(ListaVendedor }
&Lv, char DNI[]){
18
19

LPF.cab = aux;
void Mostrar(ProductoFactura PF){ aux->sgte=aux;
cout<<"\t (*) Codigo de }else{
Producto: "<<PF.codProducto<<endl; temp = LPF.cab;
cout<<"\t (*) Cantidad:
"<<PF.cantidad<<endl; while(temp->sgte !=
cout<<"\t (*) Subtotal: LPF.cab){
"<<PF.subtotal<<endl; temp = temp->sgte;
} }
temp->sgte = aux;
//OPERACIONES DE LISTA aux->sgte=LPF.cab;
PRODUCTOFACTURA----------------- }
void LPF.total ++;
Inicializa(ListaProductoFactura }
&LPF){
LPF.total = 0; void
LPF.cab = NULL; InsertarPosicion(ListaProductoFactu
} ra &LPF, ProductoFactura PF,
NodoProductoFactura *pos){
void
InsertarInicio(ListaProductoFactura if(pos == LPF.cab){
&LPF, ProductoFactura PF){ InsertarInicio(LPF, PF);
NodoProductoFactura* aux = }
new NodoProductoFactura; else{

aux->info = PF; if(pos->sgte == LPF.cab){


aux->sgte = NULL; InsertarFinal(LPF, PF);
if(LPF.cab==NULL){ }
LPF.cab=aux; else{
aux->sgte = aux;
NodoProductoFactura *aux = new
}else{ NodoProductoFactura;
NodoProductoFactura NodoProductoFactura *a_Pos;
*temp;
aux->info = PF;
temp=LPF.cab; aux->sgte = NULL;
while(temp- a_Pos=LPF.cab;
>sgte!=LPF.cab){ while(a_Pos->sgte!=pos){
temp = temp->sgte; a_Pos=a_Pos->sgte;
} }
aux->sgte = pos;
temp->sgte = aux; a_Pos->sgte=aux;
aux->sgte = LPF.cab; LPF.total++;
LPF.cab=aux; }
}
} }
LPF.total++;
} void
EliminaInicio(ListaProductoFactura
void &LPF){
InsertarFinal(ListaProductoFactura NodoProductoFactura *temp;
&LPF, ProductoFactura PF){ temp=LPF.cab;
NodoProductoFactura *aux = new
NodoProductoFactura; if(LPF.total > 0){
NodoProductoFactura *temp; NodoProductoFactura *aux;
aux=LPF.cab;
aux->info = PF; while(aux->sgte!=LPF.cab){
aux->sgte = NULL; aux=aux->sgte;
}
aux->sgte=LPF.cab->sgte;
if(LPF.cab == NULL){ LPF.cab=temp->sgte;
19
20

delete temp; void Presenta(ListaProductoFactura


LPF.total--; LPF){
cout << "\n\tProducto NodoProductoFactura *aux;
eliminado\n" << endl;
}else if(LPF.cab==NULL){
cout << "\n\tLista Vacia\n" cout << "\n\tLista Vacia.
<< endl; \n"<< endl;
}else{
system("pause"); int band=0;
} aux=LPF.cab;
while(band==0){
void cout<<"\n"<<endl;
EliminaFinal(ListaProductoFactura
&LPF){ Mostrar(aux->info);
NodoProductoFactura *temp =
LPF.cab;
NodoProductoFactura *aux= if(aux->sgte==LPF.cab){
LPF.cab; band=1;
}
if(LPF.total > 0){ aux=aux->sgte;
while(temp->sgte != }
LPF.cab)
temp = temp->sgte; }
while(aux->sgte != temp) system("pause");
aux = aux->sgte; }
aux->sgte=LPF.cab;
NodoProductoFactura
delete temp; *Buscar(ListaProductoFactura &LPF,
LPF.total--; char codProd[]){
NodoProductoFactura *aux;
cout << "\n\tProducto
Eliminado\n" << endl; int band=0;
}else aux=LPF.cab;
cout << "\n\tLista Vacia\n" while(band==0){
<< endl; if(strcmp(aux-
system("pause"); >info.codProducto, codProd) == 0){
} return aux;
}
void if(aux->sgte==LPF.cab){
EliminaPosicion(ListaProductoFactur band=1;
a &LPF, NodoProductoFactura *pos){ }
NodoProductoFactura *aux; aux=aux->sgte;
}
if(pos==LPF.cab){ return NULL;
EliminaInicio(LPF); }
}else
if(pos->sgte==LPF.cab) //*********************************
EliminaFinal(LPF); *********** FACTURA *******
else{
aux=LPF.cab; //FUNCIONES BASICAS FACTURA--------
while(aux->sgte!=pos){ ----
aux=aux->sgte;
} void inicia(Factura &F){
aux->sgte=pos->sgte; Inicializa(F.LPF);
delete pos; }
LPF.total--;
} void Llenar(Factura &F){
} cout <<"\n\t (*) Numero de
Factura: "; cin >> F.numFactura;
cout <<"\t (*) DNI de Vendedor:
"; cin >> F.DNIVendedor;
20
21

cout <<"\t (*) DNI de Cliente: NodoFactura *temp;


"; cin >> F.DNICliente;
printf("\t (*) Nombre: "); aux->info = F;
fflush(stdin); aux->sgte = NULL;
gets(F.nombre);
}
if(LF.cab == NULL){
LF.cab = aux;
void Mostrar(Factura F){ aux->sgte=aux;
cout<<"\t (*) Numero de }else{
Factura: "<<F.numFactura<<endl; temp = LF.cab;
cout<<"\t (*) DNI de Vendedor:
"<<F.DNIVendedor<<endl; while(temp->sgte !=
cout<<"\t (*) DNI de Cliente: LF.cab){
"<<F.DNICliente<<endl; temp = temp->sgte;
cout<<"\t (*) Nombre: " << }
F.DNICliente <<endl; temp->sgte = aux;
Presenta(F.LPF); aux->sgte=LF.cab;
cout<<"\t (*) Monto Total: }
"<<F.montoTotal<<endl; LF.total ++;
}
}
void InsertarPosicion(ListaFactura
//OPERACIONES DE LISTA FACTURA----- &LF, Factura F, NodoFactura *pos){

void Inicializa(ListaFactura &LF){ if(pos == LF.cab){


LF.total = 0; InsertarInicio(LF, F);
LF.cab = NULL; }
} else{

void InsertarInicio(ListaFactura if(pos->sgte == LF.cab){


&LF, Factura F){ InsertarFinal(LF, F);
NodoFactura* aux = new }
NodoFactura; else{

aux->info = F; NodoFactura *aux = new


aux->sgte = NULL; NodoFactura;
if(LF.cab==NULL){ NodoFactura *a_Pos;
LF.cab=aux;
aux->sgte = aux; aux->info = F;
aux->sgte = NULL;
}else{ a_Pos=LF.cab;
NodoFactura *temp; while(a_Pos->sgte!=pos){
a_Pos=a_Pos->sgte;
temp=LF.cab; }
while(temp->sgte!=LF.cab){ aux->sgte = pos;
temp = temp->sgte; a_Pos->sgte=aux;
} LF.total++;
}
temp->sgte = aux; }
aux->sgte = LF.cab; }
LF.cab=aux;
void EliminaInicio(ListaFactura
} &LF){
LF.total++; NodoFactura *temp;
} temp=LF.cab;

void InsertarFinal(ListaFactura if(LF.total > 0){


&LF, Factura F){ NodoFactura *aux;
NodoFactura *aux = new aux=LF.cab;
NodoFactura; while(aux->sgte!=LF.cab){
21
22

aux=aux->sgte; if(LF.cab==NULL){
} cout << "\n\tLista Vacia.
aux->sgte=LF.cab->sgte; \n"<< endl;
LF.cab=temp->sgte; }else{
delete temp; int band=0;
LF.total--; aux=LF.cab;
cout << "\n\tFactura while(band==0){
eliminada\n" << endl; Mostrar(aux->info);
}else if(aux->sgte==LF.cab){
cout << "\n\tLista Vacia\n" band=1;
<< endl; }
aux=aux->sgte;
system("pause"); }
}
}
void EliminaFinal(ListaFactura system("pause");
&LF){ }
NodoFactura *temp = LF.cab;
NodoFactura *aux= LF.cab; NodoFactura *Buscar(ListaFactura
&LF, char numFact[]){
if(LF.total > 0){ NodoFactura *aux;
while(temp->sgte != LF.cab)
temp = temp->sgte; int band=0;
while(aux->sgte != temp) aux=LF.cab;
aux = aux->sgte; while(band==0){
aux->sgte=LF.cab; if(strcmp(aux-
>info.numFactura, numFact) == 0){
delete temp; return aux;
LF.total--; }
if(aux->sgte==LF.cab){
cout << "\n\tFactura band=1;
Eliminada\n" << endl; }
}else aux=aux->sgte;
cout << "\n\tLista Vacia\n" }
<< endl; return NULL;
system("pause"); }
}
//*********************************
void EliminaPosicion(ListaFactura ************ MENU, DESARROLLO Y
&LF, NodoFactura *pos){ PROCESO DE PRODUCTO ***********
NodoFactura *aux; int opciones1(){
int rpta;
if(pos==LF.cab){
EliminaInicio(LF); system("cls");
}else cout<< "\n\t\t\t>>>>> MENU
if(pos->sgte==LF.cab) PRODUCTO <<<<<" <<endl;
EliminaFinal(LF);
else{ cout<< "\n\t(1). Inserta
aux=LF.cab; Inicio." <<endl;
while(aux->sgte!=pos){ cout<< "\t(2). Inserta
aux=aux->sgte; final." <<endl;
} cout<< "\t(3). Inserta en
aux->sgte=pos->sgte; Posicion" <<endl;
delete pos; cout<< "\t(4). Elimina Al
LF.total--; Inicio." <<endl;
} cout<< "\t(5). Elimina Al
} Final." <<endl;
cout<< "\t(6). Elimina En
void Presenta(ListaFactura LF){ Posicion" <<endl;
NodoFactura *aux; cout<< "\t(7). Buscar
Producto." <<endl;
22
23

cout<< "\t(8). Listado


Productos." <<endl; InsertarPosicion(LP,aux,pos);
cout<< "\t(9). Salir." cout << "\n\tProducto
<<endl; Agregado\n" << endl;
cout<< "\n\t\t---> }else
Ingrese Opcion: "; cin>>rpta; cout <<"\n\tCodigo No
Existe.\n "<< endl;
return rpta;
} system("pause");
//--------------------------------- }
void
RegistrarProductoInicio(ListaProduc void opBuscar(ListaProducto LP){
to &LP){ char cod[10];

NodoProducto *Pos;
Producto aux; cout<<"\n\tIngrese codigo del
cout<<"\t--------------"<<endl; producto a buscar: ",cin>> cod;
cout<<"\t LLENAR PRODUCTO
"<<endl;
cout<<"\t--------------"<<endl; Pos=Buscar(LP,cod);
Llenar(aux);
InsertarInicio(LP,aux); if (Pos !=NULL) {
cout << "\n\tProducto Mostrar(Pos->info);
Agregado\n" << endl; }
else {
system("pause"); cout <<"\n\tCodigo no
} Existe..\n"<<endl;
}
void system("pause");
RegistrarProductoFinal(ListaProduct }
o &LP){
Producto aux; void opEliminaPos(ListaProducto
cout<<"\t--------------"<<endl; &LP){
cout<<"\t LLENAR PRODUCTO char cod[10];
"<<endl;
cout<<"\t--------------"<<endl; cout << "\n\t Ingrese codigo de
Llenar(aux); producto a eliminar: "; cin >> cod;
InsertarFinal(LP,aux); NodoProducto *pos =
cout << "Producto Agregado" << Buscar(LP,cod);
endl; if (pos !=NULL) {
system("pause"); EliminaPosicion(LP, pos);
} cout << "\n\tProducto
Eliminado.\n" << endl;
void }
RegistrarProductoPosicion(ListaProd else {
ucto &LP){ cout <<"\n\tCodigo no
Producto aux; Existe..\n"<<endl;
char cod[10]; }
system("pause");
cout<<"\t--------------"<<endl; }
cout<<"\t LLENAR PRODUCTO
"<<endl; //---------------------------------
cout<<"\t--------------"<<endl;
Llenar(aux); void Proceso1(ListaProducto &LP){
cout << "\n\t - Ingrese codigo int rpta;
registrado: "; cin >> cod; do{
rpta=opciones1();
NodoProducto *pos = Buscar(LP, switch (rpta) {
cod); case
1:RegistrarProductoInicio(LP);
if (pos !=NULL) { break;
23
24

case
2:RegistrarProductoFinal(LP); //---------------------------------
break; void
case RegistrarVendedorInicio(ListaVended
3:RegistrarProductoPosicion(LP); or &LV){
break; Vendedor aux;
case cout<<"\t--------------"<<endl;
4:EliminaInicio(LP); cout<<"\t LLENAR VENDEDOR
break; "<<endl;
case cout<<"\t--------------"<<endl;
5:EliminaFinal(LP); Llenar(aux);
break; InsertarInicio(LV,aux);
case cout << "Vendedor Agregado" <<
6:opEliminaPos(LP); endl;
break; system("pause");
case 7:opBuscar(LP); }
break;
case 8:Presenta(LP); void
break; RegistrarVendedorFinal(ListaVendedo
case 9:cout << r &LV){
"Gracias. "<< endl; Vendedor aux;
break; cout<<"\t--------------"<<endl;
} cout<<"\t LLENAR VENDEDOR
}while(rpta!=9); "<<endl;
} cout<<"\t--------------"<<endl;
Llenar(aux);
//********************************* InsertarFinal(LV,aux);
******** MENU, DESARROLLO Y PROCESO cout << "Vendedor Agregado" <<
DE VENDEDOR ********************* endl;
system("pause");
int opciones2(){ }
int rpta;
void
system("cls"); RegistrarVendedorPosicion(ListaVend
edor &LV){
cout<< "\n\t\t\t>>>>> MENU Vendedor aux;
VENDEDOR <<<<<" <<endl; char dni[10];

cout<< "\n\t (1). Inserta cout<<"\t--------------"<<endl;


Inicio." <<endl; cout<<"\t LLENAR VENDEDOR
cout<< "\t (2). Inserta "<<endl;
final." <<endl; cout<<"\t-------------"<<endl;
cout<< "\t (3). Inserta en Llenar(aux);
Posicion" <<endl; cout << "\n\t - Ingrese dni
cout<< "\t (4). Elimina Al registrado: "; cin >> dni;
Inicio." <<endl;
cout<< "\t (5). Elimina Al NodoVendedor *pos = Buscar(LV,
Final." <<endl; dni);
cout<< "\t (6). Elimina En
Posicion" <<endl; if (pos !=NULL) {
cout<< "\t (7). Buscar
Vendedor." <<endl; InsertarPosicion(LV,aux,pos);
cout<< "\t (8). Listado cout << "Vendedor
Vendedores." <<endl; Agregado\n" << endl;
cout<< "\t (9). Salir." }else
<<endl; cout <<"DNI No Existe.\n
cout<< "\n\t\t---> Ingrese "<< endl;
Opcion: "; cin>>rpta;
system("pause");
return rpta; }
}
24
25

void opBuscar(ListaVendedor LV){ case


char dni[10]; 6:opEliminaPos(LV);
break;
NodoVendedor *Pos; case 7:opBuscar(LV);
cout<<"\n\tIngrese DNI del break;
vendedor a buscar: ",cin>> dni; case 8:Presenta(LV);
break;
Pos=Buscar(LV,dni); case 9:cout <<
"Gracias. "<< endl;
if (Pos !=NULL) { break;
Mostrar(Pos->info); }
} }while(rpta!=9);
else { }
cout <<"\n\tDNI no //*********************************
Existe..\n"<<endl; ************ MENU, DESARROLLO Y
} PROCESO DE FACTURA ***************
system("pause");
} int opciones3(){
int rpta;
void opEliminaPos(ListaVendedor
&LV){ system("cls");
char dni[10];
cout<< "\n\t\t\t>>>>> MENU
cout << "\n\tIngrese DNI de FACTURA <<<<<" <<endl;
vendedor a eliminar: "; cin >> dni; cout<< "\n\t (1). Inserta
NodoVendedor *pos = Inicio." <<endl;
Buscar(LV,dni); cout<< "\t (2). Inserta
if (pos !=NULL) { final." <<endl;
EliminaPosicion(LV, pos); cout<< "\t (3). Inserta en
cout << "\n\tVendedor Posicion" <<endl;
Eliminado.\n" << endl; cout<< "\t (4). Elimina Al
} Inicio." <<endl;
else { cout<< "\t (5). Elimina Al
cout <<"\n\tDNI no Final." <<endl;
Existe..\n"<<endl; cout<< "\t (6). Elimina En
} Posicion" <<endl;
system("pause"); cout<< "\t (7). Buscar
} Factura." <<endl;
cout<< "\t (8). Listado
//--------------------------------- Facturas." <<endl;
void Proceso2(ListaVendedor cout<< "\t (9). Productos
LV,ListaFactura LF){ con su mayor factura." <<endl;
int rpta; cout<< "\t (10). Salir."
do{ <<endl;
rpta=opciones2(); cout<< "\n\t\t---> Ingrese
switch (rpta) { Opcion: "; cin>>rpta;
case
1:RegistrarVendedorInicio(LV); return rpta;
break; }
case
2:RegistrarVendedorFinal(LV); //---------------------------------
break; void
case RegistrarFacturaInicio(ListaFactura
3:RegistrarVendedorPosicion(LV); &LF,ListaProducto &LP){
break; Factura aux;
case ProductoFactura aux1;
4:EliminaInicio(LV); int rpta;
break; inicia(aux);
case cout<<"\t--------------"<<endl;
5:EliminaFinal(LV); cout<<"\t LLENAR FACTURA
break; "<<endl;
25
26

cout<<"\t--------------"<<endl; system("pause");
Llenar(aux);
do{ }
Llenar(aux1,LP);
void
InsertarInicio(aux.LPF,aux1); RegistrarFacturaPosicion(ListaFactu
ra &LF,ListaProducto &LP){
aux.montoTotal+=aux1.subtotal; Factura aux;
cout<<"\n\tDesea registrar ProductoFactura aux1;
otro producto: " <<endl; int rpta;
cout<<"\n\t\t1.Si."<<endl; char num[10];
cout<<"\n\t\t2.No."<<endl;
do{ cout<<"\t--------------"<<endl;
cout<<"\n\t\t\t--> Rpta: cout<<"\t LLENAR FACTURA
";cin>>rpta; "<<endl;
}while(rpta<1 || rpta>2); cout<<"\t--------------"<<endl;
if(rpta==2){ inicia(aux);
cout<<"\n\tFactura Llenar(aux);
agregada.\t"<<endl; do{
} Llenar(aux1,LP);
}while(rpta!=2);
InsertarInicio(LF,aux); InsertarFinal(aux.LPF,aux1);

system("pause"); aux.montoTotal+=aux1.subtotal;
} cout<<"\n\tDesea registrar
otro producto: " <<endl;
void cout<<"\n\t\t1.Si."<<endl;
RegistrarFacturaFinal(ListaFactura cout<<"\n\t\t2.No."<<endl;
&LF,ListaProducto &LP){ do{
Factura aux; cout<<"\n\t\t\t--> Rpta:
ProductoFactura aux1; ";cin>>rpta;
int rpta; }while(rpta<1 || rpta>2);
inicia(aux); if(rpta==2){
cout<<"\t--------------"<<endl; cout<<"\n\tFactura
cout<<"\t LLENAR FACTURA agregada.\n"<<endl;
"<<endl; }
cout<<"\t-------------"<<endl; }while(rpta!=2);
Llenar(aux);
do{ cout << "\n\t - Ingrese numero
de factura registrada: "; cin >>
Llenar(aux1,LP); num;

InsertarFinal(aux.LPF,aux1); NodoFactura *pos = Buscar(LF,


num);
aux.montoTotal+=aux1.subtotal; if (pos !=NULL) {
cout<<"\n\tDesea registrar
otro producto: " <<endl; InsertarPosicion(LF,aux,pos);
cout<<"\n\t\t1.Si."<<endl; cout << "\n\tFactura
cout<<"\n\t\t2.No."<<endl; Agregada.\n" << endl;
}else
do{ cout <<"\n\tFactura no
cout<<"\n\t\t\t--> Rpta: Existe.\n" << endl;
";cin>>rpta; system("pause");
}while(rpta<1 || rpta>2); }
if(rpta==2){
cout<<"\n\tFactura void opBuscar(ListaFactura &LF){
agregada.\n"<<endl; char num[10];
}
}while(rpta!=2); NodoFactura *Pos;
InsertarFinal(LF,aux); cout<<"\n\tIngrese numero de
factura a Buscar: ",cin>> num;
26
27

Pos=Buscar(LF,num); LF.cab=LF.cab->sgte;
}
if (Pos !=NULL) {
Mostrar(Pos->info); for(int z=0; z<LF.total;z++){
} for(int y=0; y<LF.cab-
else { >info.LPF.total; y++){
cout <<"\n\tFactura no if(strcmp(LP.cab-
Existe..\n"<<endl; >info.codigo,LF.cab->info.LPF.cab-
} >info.codProducto)==0){
system("pause"); if(LF.cab->info.LPF.cab-
} >info.cantidad==mayor){
cout<< "\n\t\tNumero
void opEliminaPos(ListaFactura Factura: "<< LF.cab-
&LF){ >info.numFactura<< endl;
char num[10]; cout<< "\n\t\tCantidad:
"<< mayor<< endl;
cout << "\n\tIngrese numero de }
factura a eliminar: "; cin >> num; }
NodoFactura *pos = LF.cab->info.LPF.cab=LF.cab-
Buscar(LF,num); >info.LPF.cab->sgte;
if (pos !=NULL) { }
EliminaPosicion(LF, pos); LF.cab=LF.cab->sgte;
cout << "\n\tFactura }
Eliminada.\n" << endl; LP.cab=LP.cab->sgte;
} }
else {
cout <<"\n\tFactura no
Existe..\n"<<endl; system("pause");
}
system("pause"); }
} //--------------------------------
void Proceso3(ListaFactura &LF,
//REPORTE 9: Productos con su mayor ListaProducto &LP){
factura -------- int rpta;
void opReporte9(ListaFactura do{
LF,ListaProducto LP){ rpta=opciones3();
int mayor; switch (rpta) {
case
for(int x=0; x<LP.total;x++){ 1:RegistrarFacturaInicio(LF,LP);
cout <<"\n\tCodigo de break;
Producto: "<< LP.cab->info.codigo<< case
endl; 2:RegistrarFacturaFinal(LF,LP);
mayor=0; break;
for(int i=0; i<LF.total;i++){ case
for(int j=0; j<LF.cab- 3:RegistrarFacturaPosicion(LF,LP);
>info.LPF.total; j++){ break;
if(strcmp(LP.cab- case
>info.codigo,LF.cab->info.LPF.cab- 4:EliminaInicio(LF);
>info.codProducto)==0){ break;
if(LF.cab- case
>info.LPF.cab->info.cantidad> 5:EliminaFinal(LF);
mayor){ break;
mayor = LF.cab- case
>info.LPF.cab->info.cantidad; 6:opEliminaPos(LF);
} break;
} case 7:opBuscar(LF);
LF.cab- break;
>info.LPF.cab=LF.cab->info.LPF.cab- case 8:Presenta(LF);
>sgte; break;
}
27
28

case void Proceso(ListaProducto &LP,


9:opReporte9(LF,LP); ListaVendedor &LV, ListaFactura
break; LF){
case 10:cout << int rpta;
"Gracias. "<< endl; do{
break; rpta=opciones();
} switch (rpta) {
}while(rpta!=10); case 1:opciones1();
} Proceso1(LP);
//--------------------------------- break;
OPERACIONES PRINCIPALES DEL case 2:opciones2();
PROGRAMA: MENU GENERAL ****** Proceso2(LV,
int opciones(){ LF);
int rpta; break;
case 3:opciones3();
system("cls"); Proceso3(LF,LP);
cout << "\n\t\t\t---------- break;
-------------------"<<endl; case 4:cout <<
cout << "\t\t\t|\tMENU "Gracias." << endl;
PRINCIPAL |"<<endl; break;
cout << "\t\t\t------------ }
-----------------"<<endl; }while(rpta!=4);
cout<< "\n\t (1). }
PRODUCTO." <<endl; int main()
cout<< "\n\t (2). {
VENDEDOR." <<endl; ListaProducto LP;
cout<< "\n\t (3). FACTURA." ListaVendedor LV;
<<endl; ListaFactura LF;
cout<< "\n\t (4). SALIR."
<<endl; Inicializa(LP);
cout<< "\n\t\t---> Ingrese Inicializa(LV);
Opcion: "; cin>>rpta; Inicializa(LF);

return rpta; Proceso(LP,LV,LF);


}
return 0;
}

28
29

CONCLUSIONES:

 Al haber concluido el trabajo hemos tenido una experiencia nueva


en la cual hemos aprendido a elaborar las operaciones principales
una estructura de listas circulares simples.

 A demás hemos aprendido cual es la diferencia entre listas


lineales y listas circulares, y la utilización de esta misma en
programación.

 Si bien el trabajo fue concluido, al principio tuvimos discrepancias


en el grupo puesto que teníamos ideas diferentes, sin embargo
después de compartir, discutir y analizar nuestras opiniones
fuimos creando e implementando los códigos de nuestro ejercicio
resultando así el presente trabajo expuesto.

29

También podría gustarte