Está en la página 1de 2

//listas simples circular

#include<iostream>
#include<stdlib.h>
using namespace std;

struct nodo{
int nro;
struct nodo *sgte;
};

typedef struct nodo;


nodo *fin;
nodo *lista;

void menu();
void insertarInicio();
void insertarFinal();
void mostrar();
void buscarElemento();
void eliminarElemento();

int main(){
lista=NULL;
int opc;
do{
menu();
cin>>opc;
switch(opc){
case 1:
insertarInicio();
break;
case 2:
insertarFinal();
break;
case 3:
cout<<"Lista Circular"<<endl;
mostrar();
break;
case 4:
buscarElemento();
break;
case 5:
eliminarElemento();
default :
cout<<"Opcion no valida...!";
}
system("pause");
system("cls");
}while(opc!=6);
return 0;
}
void menu(){
cout<<"\t\t __________________________________________________ "<<endl;
cout<<"\t\t|---------- LISTA ENLASADA CIRCULAR -----------|"<<endl;
cout<<"\t\t|--------------------------------------------------|"<<endl;
cout<<"\t\t|--- 1. Insertar Inicio || 4. Buscar Elemento ----|"<<endl;
cout<<"\t\t|-- 2. Insertar Final || 5. Eliminar Elemento --|"<<endl;
cout<<"\t\t|-- 3. Mostrar || 6. Salir --|"<<endl;
cout<<"\t\t|__________________________________________________|"<<endl;
cout<<"\t>Seleccione una opcion: ";
}
void insertarInicio(){
nodo *nuevo;
nuevo=new struct nodo;

This study source was downloaded by 100000804985103 from CourseHero.com on 01-19-2022 14:19:13 GMT -06:00

https://www.coursehero.com/file/78945597/Lista-Circularcpp/
cout<<"\n\tInsertar al inicio";
cout<<"\n\tIngresar el dato: ";
cin>>nuevo->nro;
nuevo->sgte=NULL;
if(lista==NULL){
cout<<"Primer Elemento";
lista=nuevo;
lista->sgte=lista;
fin=nuevo;
}
else{
nuevo->sgte=lista;
lista=nuevo;
fin->sgte=lista;
}
}
void insertarFinal(){
nodo *nuevo;
nuevo=new struct nodo;
cout<<"\n\tInsertar al final";
cout<<"\n\tIngresar el dato: ";
cin>>nuevo->nro;
nuevo->sgte=NULL;
if(lista==NULL){
cout<<"Primer Elemento";
lista=nuevo;
lista->ste=lista;
fin->nuevo;
}
else{
fin->sgte=nuevo;
nuevo->sgte=lista;
fin=nuevo;
}
}
void mostrar(){
nodo *aux;
aux=lista;
while(aux!=NULL){
do{
cout<<" " <<aux->nro;
aux=aux->sgte;
i++;
}while(aux!=lista);
}
}

This study source was downloaded by 100000804985103 from CourseHero.com on 01-19-2022 14:19:13 GMT -06:00

https://www.coursehero.com/file/78945597/Lista-Circularcpp/
Powered by TCPDF (www.tcpdf.org)

También podría gustarte