Advertisement
Guest User

Untitled

a guest
Apr 21st, 2015
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct aluno{
  5. int num;
  6. char nome[100];
  7. char curso[100];
  8. }INFO;
  9.  
  10. typedef struct elem{
  11. INFO nodo;
  12. struct elem *seguinte;
  13. struct elem *anterior;
  14. }ELEMENTO;
  15.  
  16. void inserirIni(ELEMENTO **iniLista,ELEMENTO **fimLista,INFO new_info){
  17.  
  18. ELEMENTO *novo;
  19.  
  20. novo=(ELEMENTO*)calloc(1,sizeof(ELEMENTO));
  21.  
  22. if(novo==NULL){
  23. printf("ERRO ao reservar memoria\n");
  24. return;
  25. }
  26.  
  27. novo->nodo=new_info;
  28. novo->seguinte=NULL;
  29. novo->anterior=NULL;
  30. if(iniLista==NULL){
  31. *iniLista=novo;
  32. *fimLista=novo;
  33. }else{
  34. novo->seguinte=*iniLista;
  35. (*iniLista)->anterior=novo;
  36. *iniLista=novo;
  37. }
  38. }
  39.  
  40. void inserirFim(ELEMENTO **iniLista,ELEMENTO **fimLista,INFO new_info){
  41.  
  42. ELEMENTO *novo;
  43.  
  44. novo=(ELEMENTO*)calloc(1,sizeof(ELEMENTO));
  45.  
  46. if(novo==NULL){
  47. printf("ERRO ao reservar memoria\n");
  48. return;
  49. }
  50.  
  51. novo->nodo=new_info;
  52. novo->seguinte=NULL;
  53. novo->anterior=NULL;
  54.  
  55. if(*fimLista==NULL){
  56. *iniLista=novo;
  57. *fimLista=novo;
  58. }else{
  59. novo->anterior=*fimLista;
  60. (*fimLista)->seguinte=novo;
  61. *fimLista=novo;
  62. }
  63. }
  64.  
  65. void imprimeLista(ELEMENTO *iniLista){
  66.  
  67. ELEMENTO *aux=NULL;
  68.  
  69. if(iniLista==NULL){
  70. printf("Lista vazia\n");
  71. return;
  72. }
  73.  
  74. for(aux=iniLista;aux!=NULL;aux=aux->seguinte){
  75. printf("%i %s %s\n", aux->nodo.num,aux->nodo.nome,aux->nodo.curso);
  76. }
  77. }
  78.  
  79. void imprimLista(ELEMENTO *fimLista){
  80.  
  81. ELEMENTO *aux=NULL;
  82.  
  83. if(fimLista==NULL){
  84. printf("Lista vazia\n");
  85. return;
  86. }
  87.  
  88. aux=fimLista;
  89.  
  90. while(aux!=NULL){
  91. printf("%i %s %s\n", aux->nodo.num,aux->nodo.nome,aux->nodo.curso);
  92. aux=aux->anterior;
  93. }
  94. }
  95.  
  96. int main(int argc, char *argv[])
  97. {
  98. ELEMENTO *iniLista=NULL;
  99. ELEMENTO *fimLista=NULL;
  100.  
  101.  
  102. system("PAUSE");
  103. return 0;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement