Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- /* run this program using the console pauser or add your own getch, system("pause") or input loop */
- typedef struct lista{
- int numero;
- char nome[30];
- struct lista*prox,*ant;
- }lista;
- lista *inicio,*temp,*fim;
- void inseririnicio(){
- int c;
- do{
- temp=(lista*)malloc(sizeof(lista));
- printf("Numero:");
- scanf("%d",&temp->numero);
- printf("Nome:");
- do{
- gets(temp->nome);
- }while(strlen(temp->nome)==0);
- if(inicio==NULL){
- inicio=temp;
- fim=inicio;
- inicio->prox=inicio->ant=NULL;
- }
- else{
- temp->prox=inicio;
- inicio->ant=temp;
- temp->ant=NULL;
- inicio=temp;
- }
- printf("Continuar?");
- scanf("%d",&c);
- }while(c==1);
- temp=inicio;
- while(temp!=NULL){
- printf("\nNumero:%d\nNome:%s\n\n",temp->numero,temp->nome);
- temp=temp->prox;
- }
- }
- void inserirfim(){
- int c;
- do{
- temp=(lista*)malloc(sizeof(lista));
- printf("Numero:");
- scanf("%d",&temp->numero);
- printf("Nome:");
- do{
- gets(temp->nome);
- }while(strlen(temp->nome)==0);
- if(inicio==NULL){
- inicio=temp;
- inicio->prox=inicio->ant=NULL;
- }
- else{
- fim->prox=temp;
- temp->ant=fim;
- temp->prox=NULL;
- fim=temp;
- }
- printf("Continuar?");
- scanf("%d",&c);
- }while(c==1);
- temp=inicio;
- while(temp!=NULL){
- printf("\nNumero:%d\nNome:%s\n\n",temp->numero,temp->nome);
- temp=temp->prox;
- }
- }
- void listarinicio(){
- temp=inicio;
- while(temp!=NULL){
- printf("\nNumero:%d\nNome:%s\n\n",temp->numero,temp->nome);
- temp=temp->prox;
- }
- }
- void listarfim(){
- temp=fim;
- while(temp!=NULL){
- printf("\nNumero:%d\nNome:%s\n\n",temp->numero,temp->nome);
- temp=temp->ant;
- }
- }
- int main() {
- int op;
- do{
- printf("1-Inserir no início \n");
- printf("2-Inserir no fim\n");
- printf("3-Listar a lista inicio->fim\n");
- printf("4-Listar a lista fim<-inicio \n");
- printf("5-Sair\n");
- printf("Tua Escolha: ");
- scanf("%d",&op);
- system("cls");
- switch(op){
- case 1: inseririnicio();
- break;
- case 2: inserirfim();
- break;
- case 3: listarinicio();
- break;
- case 4: listarfim();
- break;
- }
- }while (op!=5);
- system("cls");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment