Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. struct Node{
  5. int num;
  6. struct Node *prox;
  7. };
  8. typedef struct Node node;
  9.  
  10.  
  11. int tam;
  12.  
  13. void inicia(node *Lista);
  14. void insereInicio(int val, node *Lista);
  15. void exibe(node *LISTA);
  16.  
  17. int main(){
  18.  
  19. node *LISTA = (node *) malloc(sizeof(node));
  20.  
  21. if(!LISTA){
  22. printf("Sem memoria disponivel!\n");
  23. exit(1);
  24. }else{
  25. inicia(LISTA);
  26. }
  27.  
  28. int val;
  29.  
  30. printf("Insira uma sequencia de numeros inteiros N. -- digite -1 para encerrar ---\n");
  31.  
  32. while (1){
  33.  
  34. scanf("%d",&val);
  35. if (val == -1){
  36. break;
  37. }else{
  38. insereInicio(val ,LISTA);
  39. }
  40. }
  41.  
  42. exibe(LISTA);
  43.  
  44. calc(LISTA);
  45.  
  46. return 0;
  47. }
  48. /////////////////////////////////////////////////////
  49. int vazia(node *LISTA){
  50.  
  51. if(LISTA->prox == NULL)
  52. return 1;
  53. else
  54. return 0;
  55.  
  56.  
  57. }
  58. void inicia(node *LISTA){
  59.  
  60. LISTA->prox = NULL;
  61.  
  62. }
  63.  
  64. void insereInicio(int val, node *LISTA){
  65.  
  66. node *novo=(node *) malloc(sizeof(node));
  67. novo->num = val;
  68. node *oldHead = LISTA->prox;
  69.  
  70. LISTA->prox = novo;
  71. novo->prox = oldHead;
  72.  
  73.  
  74. }
  75. void exibe(node *LISTA){
  76.  
  77. system("clear");
  78. if(vazia(LISTA)){
  79. printf("Lista vazia!\n\n");
  80. return ;
  81. }
  82.  
  83. node *tmp;
  84. tmp = LISTA->prox;
  85. printf("Lista:");
  86. while( tmp != NULL){
  87. printf("%5d", tmp->num);
  88. tmp = tmp->prox;
  89. }
  90. printf("\n ");
  91. int count;
  92. for(count=0 ; count < tam ; count++)
  93. printf(" ^ ");
  94. printf("\nOrdem:");
  95. for(count=0 ; count < tam ; count++)
  96. printf("%5d", count+1);
  97.  
  98.  
  99. printf("\n\n");
  100. }
  101.  
  102.  
  103. void calc(node *LISTA){
  104.  
  105. int vet[9];
  106. int valor_lista, maior = 0, posi;
  107.  
  108. node *tmp;
  109. tmp = LISTA->prox;
  110.  
  111. for(int i=0; i<=9; i++){
  112. vet[i] = 0;
  113. }
  114.  
  115. while(tmp != NULL){
  116. valor_lista = tmp->num;
  117. if (valor_lista == 0){
  118. vet[0]++;
  119. }
  120. else if (valor_lista == 1){
  121. vet[1]++;
  122. }
  123. else if (valor_lista == 2){
  124. vet[2]++;
  125. }
  126. else if (valor_lista == 3){
  127. vet[3]++;
  128. }
  129. else if (valor_lista == 4){
  130. vet[4]++;
  131. }
  132. else if (valor_lista == 5){
  133. vet[5]++;
  134. }
  135. else if (valor_lista == 6){
  136. vet[6]++;
  137. }
  138. else if (valor_lista == 7){
  139. vet[7]++;
  140. }
  141. else if (valor_lista == 8){
  142. vet[8]++;
  143. }
  144. else if (valor_lista == 9){
  145. vet[9]++;
  146. }
  147. tmp = tmp->prox;
  148. }
  149.  
  150. for(int i=9; i>=0; i--){
  151. if (vet[i] >= maior){
  152. maior = vet[i];
  153. posi = i;
  154. }
  155. }
  156.  
  157. printf("maior %d \n", maior);
  158.  
  159. for(int i=0; i<=9; i++){
  160. if (posi == i){
  161. printf("%d ocorreu %d vez(es) <<<< maior ocorrencia \n",i, vet[i]);
  162. }else{
  163. printf("%d ocorreu %d vez(es) \n",i, vet[i]);
  164. }
  165. }
  166.  
  167.  
  168. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement