fork download
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. typedef struct dadoNo {
  6.  
  7. char nome[20];
  8.  
  9. } DadoNo;
  10.  
  11. typedef struct no{
  12.  
  13. struct no* prox;
  14. struct no* ant;
  15. int pos;
  16. DadoNo dado;
  17.  
  18. } No;
  19.  
  20. typedef struct list {
  21.  
  22. int size;
  23. No* head;
  24.  
  25. } Lista;
  26.  
  27. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  28.  
  29. int listVazia (Lista* list){ // <----------- OK
  30.  
  31. return(list->size == 0);
  32. }
  33.  
  34. Lista* criarlist (){ // <----------- OK
  35.  
  36. Lista* list = (Lista*)malloc(sizeof(Lista));
  37. list->size = 0;
  38. list->head = NULL;
  39. return list;
  40. }
  41.  
  42. No* Busca ( Lista *list, char nome[20]){ // <----------- OK
  43.  
  44. No* ptr = list->head;
  45.  
  46. while (ptr != NULL){
  47.  
  48. if ( nome[0] != ptr->dado.nome[0]){
  49.  
  50. ptr = ptr->prox;
  51. }
  52.  
  53. else {
  54.  
  55. int i = 1, certa = 0;
  56.  
  57. for (i ; i < (int)strlen(nome) ; i++ ){
  58.  
  59. if (nome[i] == ptr->dado.nome[i]){
  60.  
  61. continue;
  62. }
  63.  
  64. else{
  65.  
  66. certa++;
  67. }
  68. }
  69.  
  70. if (certa == 0){
  71.  
  72. return ptr;
  73. break;
  74. }
  75.  
  76. else{
  77.  
  78. ptr = ptr->prox;
  79. }
  80. }
  81. }
  82. }
  83.  
  84. void Insere (Lista* list){ // <----------- OK
  85.  
  86. int i, p = (list->size);
  87. DadoNo dado;
  88. No* n = (No*) malloc(sizeof(No));
  89. n->ant = list->head;
  90.  
  91. scanf("%s", dado.nome);
  92.  
  93. if (Busca(list, dado.nome) == NULL){
  94.  
  95. n->dado = dado;
  96. n->prox = list->head;
  97. list->head = n;
  98. list->size++;
  99.  
  100. n->pos = p;
  101. }
  102.  
  103. else{
  104.  
  105. printf("ESTE NOME JA EXISTE !\n");
  106. }
  107. }
  108. ////////////////////////////////////////////////////////////////////////////////////////////////////
  109.  
  110. void InsereList(Lista* list, int Num_pessoas){ // <----------- OK
  111.  
  112. //printf("i \n");
  113.  
  114. int i;
  115.  
  116. for (i = 0; i < Num_pessoas ; i++){
  117.  
  118. Insere(list);
  119. }
  120. }
  121.  
  122. void RemoverDados ( Lista *list){
  123.  
  124. //printf("r \n");
  125. char nome[20];
  126. int i = 0;
  127. printf("DIGITE O NOME DA PESSOA QUE DESEJA REMOVER : \n");
  128. scanf("%s", nome);
  129.  
  130. No* atual = Busca(list, nome);
  131. No* aux = (No*)malloc(sizeof(No));
  132. No* aux1 = (No*)malloc(sizeof(No));
  133.  
  134. if (!listVazia(list)){
  135.  
  136. if (atual != NULL){
  137.  
  138. if (atual->pos == 0 ){
  139.  
  140.  
  141. }
  142.  
  143. else if( atual == list->head){
  144.  
  145. list->head = atual->ant;
  146. }
  147.  
  148. else {
  149.  
  150. atual->prox->ant = atual->ant;
  151. atual->ant->prox = atual->prox;
  152. }
  153.  
  154. free(atual);
  155. list->size--;
  156. }
  157.  
  158. else{
  159.  
  160. printf("ESTE NOME NAO PERTENCE A LISTA .\n"); // <---- LEMBRAR DE TIRAR ISTO !
  161. printf("\n");
  162. }
  163. }
  164. }
  165. //////////////////////////////////////////////////////////////////////////////////////////////////
  166.  
  167. int main (){
  168.  
  169. Lista* l = criarlist();
  170.  
  171. InsereList(l,1);
  172. printf("\n");
  173. RemoverDados(l);
  174.  
  175. No* ptr = l->head;
  176.  
  177. while( ptr != NULL){
  178.  
  179. printf("NOME : %s \n", ptr->dado.nome);
  180.  
  181. ptr = ptr->prox;
  182. printf("\n");
  183. }
  184. }
Success #stdin #stdout 0s 10320KB
stdin
Standard input is empty
stdout
DIGITE O NOME DA PESSOA QUE DESEJA REMOVER : 
ESTE NOME NAO PERTENCE A LISTA .

NOME :