Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct Banco{
  5. int numero_conta;
  6. char nome_cliente[30];
  7. float saldo;
  8. struct Banco *atras;
  9. struct Banco *agora;
  10. struct Banco *prox;
  11. struct Banco *ant;
  12. };
  13. typedef struct Banco node;
  14.  
  15. void inicia(node *LISTA);
  16. int menu(void);
  17. void opcao(node *LISTA, int op);
  18. node *criaNo();
  19. void insereFim(node *LISTA);
  20. void insereInicio(node *LISTA);
  21. void exibe(node *LISTA);
  22. void libera(node *LISTA);
  23. void excluir (node *LISTA);
  24.  
  25.  
  26. int main(void)
  27. {
  28. node *LISTA = (node *) malloc(sizeof(node));
  29. if(!LISTA){
  30. printf("Sem memoria disponivel!n");
  31. exit(1);
  32. }
  33. inicia(LISTA);
  34. int opt;
  35.  
  36. do{
  37. opt=menu();
  38. opcao(LISTA,opt);
  39. }while(opt);
  40.  
  41. free(LISTA);
  42. return 0;
  43. }
  44.  
  45. void inicia(node *LISTA)
  46. {
  47. LISTA->prox = NULL;
  48. }
  49.  
  50. int menu(void)
  51. {
  52. int opt;
  53.  
  54. printf("Escolha a opcaon");
  55. printf("0. Sairn");
  56. printf("1. Exibir listan");
  57. printf("2. Adicionar cliente no inicion");
  58. printf("3. Adicionar cliente no finaln");
  59. printf("4. Zerar listan");
  60. printf("5. Excluir cliente especificon");
  61. printf("Opcao: "); scanf("%d", &opt);
  62.  
  63. return opt;
  64. }
  65.  
  66. void opcao(node *LISTA, int op)
  67. {
  68. switch(op){
  69. case 0:
  70. libera(LISTA);
  71. break;
  72.  
  73. case 1:
  74. exibe(LISTA);
  75. break;
  76.  
  77. case 2:
  78. insereInicio(LISTA);
  79. break;
  80.  
  81. case 3:
  82. insereFim(LISTA);
  83. break;
  84.  
  85. case 4:
  86. inicia(LISTA);
  87. break;
  88.  
  89.  
  90. default:
  91. printf("Comando invalidonn");
  92. }
  93. }
  94.  
  95. int vazia(node *LISTA)
  96. {
  97. if(LISTA->prox == NULL)
  98. return 1;
  99. else
  100. return 0;
  101. }
  102.  
  103.  
  104. void insereFim(node *LISTA)
  105. {
  106. node *novo=(node *) malloc(sizeof(node));
  107. if(!novo){
  108. printf("Sem memoria disponivel!n");
  109. exit(1);
  110. }
  111. //Comeco ediчуo do professor
  112. printf("Numero conta: "); scanf("%d", &novo->numero_conta);
  113. printf("Nome: "); scanf("%s", novo->nome_cliente);
  114. printf("Saldo: "); scanf("%f", &novo->saldo);
  115. novo->prox = NULL;
  116. //Fim da ediчуo do professor
  117.  
  118. if(vazia(LISTA))
  119. LISTA->prox=novo;
  120. else{
  121. node *tmp = LISTA->prox;
  122.  
  123. while(tmp->prox != NULL)
  124. tmp = tmp->prox;
  125.  
  126. tmp->prox = novo;
  127. }
  128. }
  129.  
  130. void insereInicio(node *LISTA)
  131. {
  132. node *novo=(node *) malloc(sizeof(node));
  133. if(!novo){
  134. printf("Sem memoria disponivel!n");
  135. exit(1);
  136. }
  137. printf("Numero conta: "); scanf("%d", &novo->numero_conta);
  138. printf("Nome: "); scanf("%s", novo->nome_cliente);
  139. printf("Saldo: "); scanf("%f", &novo->saldo);
  140.  
  141. node *oldHead = LISTA->prox;
  142.  
  143. LISTA->prox = novo;
  144. novo->prox = oldHead;
  145. }
  146.  
  147. void exibe(node *LISTA)
  148. {
  149. if(vazia(LISTA)){
  150. printf("Lista vazia!nn");
  151. return ;
  152. }
  153.  
  154. node *tmp;
  155. tmp = LISTA->prox;
  156. //Edicao do professor ("%d %s %fn", tmp->numero_conta, tmp->nome_cliente, tmp->saldo)
  157. while( tmp != NULL){
  158. printf("n");
  159. printf("Numero conta: %dn", tmp->numero_conta);
  160. printf("Nome: %sn", tmp->nome_cliente);
  161. printf("Saldo: %fn", tmp->saldo);
  162. printf("n");
  163. tmp = tmp->prox;
  164. }
  165. printf("nn");
  166. }
  167.  
  168. void libera(node *LISTA)
  169. {
  170. if(!vazia(LISTA)){
  171. node *proxNode,
  172. *atual;
  173.  
  174. atual = LISTA->prox;
  175. while(atual != NULL){
  176. proxNode = atual->prox;
  177. free(atual);
  178. atual = proxNode;
  179. }
  180. }
  181. }
  182.  
  183. case 5:
  184. excluir(LISTA);
  185. break;
  186.  
  187. undefined reference to `excluir'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement