//preciso disto ate amanha
#include <iostream>
#include <iomanip>
#include <math.h>
#include <locale.h>
#include <cstring>
#include <cstdio>
#include <conio.h>
#include <cstdlib>
using namespace std;
struct elemento
{
int info;
struct elemento*anterior;
struct elemento*prox;
};
typedef struct elemento Elemento;
struct elemento *primeiro;
struct elemento *ultimo;
Elemento * lst_cria(void)
{
return NULL;
}
void lst_insere(int x)
{
struct Elemento * aux;
aux = (struct Elemento*)malloc(sizeof(struct Elemento));
aux->dados = x;
ultimo->prox = aux;
aux->ant = ultimo;
aux->prox = NULL;
ultimo = ultimo->prox;
aux = NULL;
free(aux);
}
void lst_imprime(elemento * lst)
{
Elemento * p;
for(p = lst; p != NULL; p = p->prox)
printf("info=%d\n", p->info);
}
int lst_vazia(Elemento * lst)
{
return(lst == NULL);
}
Elemento * lst_retira(int x)
{
int teste = 0;
struct Elemento*aux;
aux = primeiro;
while(aux != NULL )
{
if(aux->dados == x)
{
if(aux->prox == NULL)
{
cout << "Removido" << aux->dados << endl;
}
ultimo = ultimo->ant;
ultimo->prox = NULL;
free(aux);
aux = NULL;
teste = 1;
}
else
{
cout << "removido" << aux->dados << endl;
teste = 1;
aux->ant->prox = aux->prox;
aux->prox->ant = aux->ant;
free(aux);
aux = NULL;
}
else
{
aux = aux->prox;
if(teste == 0)
{
cout << "Nenhum valor encontado!!! :(" << endl;
}
}
}
Elemento *lst_busca(Elemento * lst, int v)
{
Elemento*p;
for(p = lst; p != NULL; p = p->prox)
{
if(p->info == v)
return p;
}
return NULL;
}
void lst_libera(Elemento * lst)
{
Elemento*p = lst;
while(p != NULL)
{
Elemento*t = p->prox;
free(p);
p = t;
}
}
Elemento * lst_insere_ordenado(Elemento * lst, int val)
{
Elemento * novo;
Elemento * a = NULL;
Elemento * p = lst;
while(p != NULL && p->info < val)
{
a = p;
p = p->prox;
}
novo = (Elemento * )malloc(sizeof(Elemento));
novo->info = val;
if(a == NULL)
{
novo->prox = lst;
lst = novo;
}
else
{
novo->prox = a ->prox;
a->prox = novo;
}
return lst;
}
void imprime_lista_ordem_direta(Elemento * lst)
{
if( lst_vazia(lst))
{
printf("\n\nA lista esta vazia.\n\n");
}
while(lst != NULL)
{
printf(" %c", lst->info);
lst = lst->prox;
}
}
void imprime_lista_ordem_inversa(Elemento * lst_cria)
{
if(lst_vazia(lst_cria))
{
printf("\n\nA lista esta vazia.\n\n");
}
else
while(lst_cria->prox != NULL)
{
lst_cria = lst_cria->prox;
}
printf("\nA lista eh:\n\n");
while(lst_cria != NULL)
{
printf(" %c", lst_cria->info);
lst_cria = lst_cria->anterior;
}
}
int main()
{
setlocale(LC_ALL, "Portuguese"); // habilita a estrutura ortográfica em português
int opcao, val;
Elemento * lst;
Elemento *lst2;
lst = lst_cria();
cout << "digite a opcao,para sair (-1)" << endl;
cin >> opcao;
while(opcao != -1)
{
cout << "1-Inserir" << endl;
cout << "2-Ordenados" << endl;
cout << "3-Buscar" << endl;
cout << "4-Imprimir F" << endl;
cout << "5-Imprimir I" << endl;
cout << "6-Excluir" << endl;
cout << "7-Sair" << endl;
cin >> opcao;
switch(opcao)
{
case 1:
cout << "voce digitou a opcao Inserir-Insira" << endl;
cin >> val;
lst = lst_insere(lst, val);
break;
case 2:
cout << "voce digitou a opcao Ordenados-Ordene" << endl;
cin >> val;
lst = lst_insere_ordenado(lst, val);
break;
case 3:
if((lst_vazia(lst) == 1))
{
cout << "Vazia" << endl;
}
else
{
cin >> val;
lst2 = lst_busca(lst, val);
}
case 4:
imprime_lista_ordem_direta(lst);
break;
case 5:
imprime_lista_ordem_inversa(lst);
case 6:
cout << "Digite o numero a ser retirado" << endl;
cin >> val;
if(lst_retira(lst, val))
{
cout << "nao existe" << endl;
}
break;
default:
cout << "nao foi possivel tente novamente!!!" << endl;
break;
cout << "digite a opcao,para sair (-1)" << endl;
cin >> opcao;
}
}
return 0;
}