// LISTA ENCADEADA SIMPLES
#include <iostream>
#include <conio.h>
#include <stdlib.h>
#include <locale.h>
using namespace std;
int main(){
setlocale(LC_ALL, "Portuguese");
struct LISTA{
int num;
LISTA *prox;
};
LISTA *inicio = NULL;
LISTA *fim = NULL;
LISTA *aux;
LISTA *anterior;
int op, numero, achou;
do{
system("cls");
cout<<"\nMenu de OPÇÕES\n";
cout<<"\n1 - Inserir no início da lista";
cout<<"\n2 - Inserir no fim da lista";
cout<<"\n3 - Consultar toda a lista";
cout<<"\n4 - Remover da lista";
cout<<"\n5 - Esvaziar a lista";
cout<<"\n6 - Sair";
cout<<"\nDigite a sua opção: ";
cin>>op;
if(op <1 || op>6){
cout<<"Opção Inválida\n";
getch();
}
if(op ==1){
cout<<"\nDigite o número a ser inserido no início da lista: ";
LISTA *novo = new LISTA();
//cin>>*novo.num;
cin>>novo->num;
if(inicio == NULL){
inicio = novo;
fim = novo;
fim->prox = NULL;
}else{
novo->prox=inicio;
inicio=novo;
}
cout<<"Numero inserido no início da lista";
getch();
}
if(op == 2){
cout<<"\nDigite o número a ser inserido no fim da lista: ";
LISTA *novo = new LISTA();
cin>>novo->num;
if(inicio == NULL){
inicio = novo;
fim = novo;
fim->prox = NULL;
}
else{
fim->prox = novo;
fim = novo;
fim->prox = NULL;
}
cout<<"Número inserido no fim da lista";
getch();
}
if(op==3){
if(inicio == NULL){
cout<<"Lista vazia\n";
getch();
}
else{
cout<<"\nConsultando toda a lista\n";
aux = inicio;
while(aux !=NULL){
cout<<aux->num<<" ";
aux = aux->prox;
}
getch();
}
}
}while(op != 6);
system("pause");
return 0;
}
Replies to ListaEncadeadaSimples_B_3
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}