Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct no
- {
- int info;
- struct no*prox;
- struct no*ant;
- };
- typedef struct no* noPtr;
- noPtr inicio = NULL;
- // Escopo das funcoes
- int menu();
- bool listaVazia();
- void inserir();
- void listar();
- void remover();
- // termino do escopo
- int main()
- {
- int valor;
- do
- {
- valor = menu();
- switch(valor)
- {
- case 1:
- inserir();
- break;
- case 2:
- listar();
- break;
- case 3:
- remover();
- break;
- case 0:
- break;
- }
- }
- while(valor != 0);
- return 0;
- }
- int menu()
- {
- int op;
- cout << "Digite um numero para comecar\n ";
- cout << "Digite 1 para inserir " << endl;
- cout << "Digite 2 para listar " << endl;
- cout << "Digite 3 para remover " << endl;
- cin >> op;
- return op;
- }
- bool listaVazia()
- {
- if(inicio == NULL)
- return true;
- else
- {
- return false;
- }
- }
- void inserir ()
- {
- noPtr p = new no;
- cout << "Digite um numero que queira inserir na lista " << endl;
- cin >> p->info;
- if(listaVazia())
- {
- inicio = p;
- p->prox = inicio;
- p->ant = inicio;
- }
- else
- {
- p->ant = inicio->ant;
- p->prox = inicio;
- inicio->ant->prox = p;
- inicio->ant = p;
- inicio = p;
- }
- }
- void listar()
- {
- if(!listaVazia())
- {
- noPtr aux = inicio;
- do
- {
- cout << aux->info << endl;
- aux = aux->prox;
- }
- while(aux != inicio);
- }
- else
- {
- cout << "Lista Vazia ! \n";
- }
- }
- void remover()
- {
- if(!listaVazia())
- {
- cout << "Digite um numero para remover, caso ele exista " << endl;
- int num;
- cin >> num;
- noPtr aux = inicio;
- do
- {
- if( aux->info == num )
- {
- aux->prox->ant = aux->ant;
- aux->ant->prox = aux->prox;
- delete(aux);
- if( aux == inicio )
- inicio = NULL;
- break;
- }
- aux = aux->prox;
- }
- while( aux != inicio );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement