Advertisement
veto14

mene

May 22nd, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. typedef struct list{
  6. char nome[81];
  7. char mat[8];
  8. char turma;
  9. float p1;
  10. float p2;
  11. float p3;
  12. list* next;
  13. }Lista;
  14.  
  15. Lista* new_list(){
  16. return NULL;
  17. }
  18.  
  19. Lista* lst_insereord (Lista* lst, char* nome, char* matricula, char turma, float p1, float p2, float p3){
  20. Lista* new_l;
  21. Lista* ant = NULL;
  22. Lista* p = lst;
  23. while(p != NULL && strcmp(nome,p->nome)>=0){
  24. ant = p;
  25. p = p->next;
  26. }
  27. new_l = (Lista*)malloc(sizeof(Lista));
  28. strcpy(new_l->nome,nome);
  29. strcpy(new_l->mat,matricula);
  30. new_l->p1 = p1;
  31. new_l->p2 = p2;
  32. new_l->p3 = p3;
  33. new_l->turma = turma;
  34. if(ant == NULL){
  35. new_l->next = lst;
  36. lst = new_l;
  37. }
  38. else{
  39. new_l->next = ant->next;
  40. ant->next = new_l;
  41. }
  42. return lst;
  43. }
  44.  
  45. void lst_print(Lista* lst){
  46. Lista* aux;
  47. for(aux = lst; aux!=NULL; aux = aux->next){
  48. printf("Conteudo %s + %s\n", aux->nome, aux->mat);
  49. }
  50. }
  51.  
  52. int lst_void (Lista* lst){
  53. return (lst == NULL);
  54. }
  55.  
  56. Lista* lst_search (Lista* lst, char* nome){
  57. Lista* search;
  58. for(search = lst; search!=NULL; search = search->next){
  59. if(strcmp(nome, search->nome) == 0){
  60. return search;
  61. }
  62. }
  63. return NULL;
  64. }
  65.  
  66. Lista* lst_remove (Lista* lst, char* nome){
  67. Lista* anterior = NULL;
  68. Lista* aux = lst;
  69. while(aux != NULL && strcmp(nome,aux->nome) != 0){
  70. anterior = aux;
  71. aux = aux->next;
  72. }
  73. if(aux == NULL){
  74. return lst;
  75. }
  76. if(anterior == NULL){
  77. lst = aux->next;
  78. }
  79. else{
  80. anterior->next = aux->next;
  81. }
  82. printf("%d Desalocado com Sucesso!\n",aux->nome);
  83. free(aux);
  84. return lst;
  85. }
  86.  
  87. Lista* lst_copys(Lista* lst){
  88. Lista* p = lst;
  89. Lista* new_l = new_list();
  90. for(p = lst; p != NULL; p = p->next){
  91. new_l = lst_insereord(new_l,p->nome,p->mat,p->turma,p->p1,p->p2,p->p3);
  92. }
  93. return new_l;
  94. }
  95.  
  96. void lst_destroy(Lista* lst){
  97. Lista* aux = lst;
  98. while(aux != NULL){
  99. Lista* t = aux->next;
  100. free(aux);
  101. aux = t;
  102. }
  103. }
  104.  
  105. int main(void){
  106. Lista* list;
  107. Lista* copy;
  108. list = new_list();
  109. copy = new_list();
  110. char nome[81],mat[81];
  111. for(int i=0; i<3; i++){
  112. fgets(nome,81,stdin);
  113. fgets(mat,81,stdin);
  114. list = lst_insereord(list,nome,mat,'1',2.0,3.0,4.0);
  115. }
  116. copy = lst_copyss(list);
  117. lst_print(copy);
  118. return 0;
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement