Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct aluno{
- int num;
- char nome[100];
- char curso[100];
- }INFO;
- typedef struct elem{
- INFO nodo;
- struct elem *seguinte;
- struct elem *anterior;
- }ELEMENTO;
- void inserirIni(ELEMENTO **iniLista,ELEMENTO **fimLista,INFO new_info){
- ELEMENTO *novo;
- novo=(ELEMENTO*)calloc(1,sizeof(ELEMENTO));
- if(novo==NULL){
- printf("ERRO ao reservar memoria\n");
- return;
- }
- novo->nodo=new_info;
- novo->seguinte=NULL;
- novo->anterior=NULL;
- if(iniLista==NULL){
- *iniLista=novo;
- *fimLista=novo;
- }else{
- novo->seguinte=*iniLista;
- (*iniLista)->anterior=novo;
- *iniLista=novo;
- }
- }
- void inserirFim(ELEMENTO **iniLista,ELEMENTO **fimLista,INFO new_info){
- ELEMENTO *novo;
- novo=(ELEMENTO*)calloc(1,sizeof(ELEMENTO));
- if(novo==NULL){
- printf("ERRO ao reservar memoria\n");
- return;
- }
- novo->nodo=new_info;
- novo->seguinte=NULL;
- novo->anterior=NULL;
- if(*fimLista==NULL){
- *iniLista=novo;
- *fimLista=novo;
- }else{
- novo->anterior=*fimLista;
- (*fimLista)->seguinte=novo;
- *fimLista=novo;
- }
- }
- void imprimeLista(ELEMENTO *iniLista){
- ELEMENTO *aux=NULL;
- if(iniLista==NULL){
- printf("Lista vazia\n");
- return;
- }
- for(aux=iniLista;aux!=NULL;aux=aux->seguinte){
- printf("%i %s %s\n", aux->nodo.num,aux->nodo.nome,aux->nodo.curso);
- }
- }
- void imprimLista(ELEMENTO *fimLista){
- ELEMENTO *aux=NULL;
- if(fimLista==NULL){
- printf("Lista vazia\n");
- return;
- }
- aux=fimLista;
- while(aux!=NULL){
- printf("%i %s %s\n", aux->nodo.num,aux->nodo.nome,aux->nodo.curso);
- aux=aux->anterior;
- }
- }
- int main(int argc, char *argv[])
- {
- ELEMENTO *iniLista=NULL;
- ELEMENTO *fimLista=NULL;
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement