Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- struct Node{
- int num;
- struct Node *prox;
- };
- typedef struct Node node;
- int tam;
- void inicia(node *Lista);
- void insereInicio(int val, node *Lista);
- void exibe(node *LISTA);
- int main(){
- node *LISTA = (node *) malloc(sizeof(node));
- if(!LISTA){
- printf("Sem memoria disponivel!\n");
- exit(1);
- }else{
- inicia(LISTA);
- }
- int val;
- printf("Insira uma sequencia de numeros inteiros N. -- digite -1 para encerrar ---\n");
- while (1){
- scanf("%d",&val);
- if (val == -1){
- break;
- }else{
- insereInicio(val ,LISTA);
- }
- }
- exibe(LISTA);
- calc(LISTA);
- return 0;
- }
- /////////////////////////////////////////////////////
- int vazia(node *LISTA){
- if(LISTA->prox == NULL)
- return 1;
- else
- return 0;
- }
- void inicia(node *LISTA){
- LISTA->prox = NULL;
- }
- void insereInicio(int val, node *LISTA){
- node *novo=(node *) malloc(sizeof(node));
- novo->num = val;
- node *oldHead = LISTA->prox;
- LISTA->prox = novo;
- novo->prox = oldHead;
- }
- void exibe(node *LISTA){
- system("clear");
- if(vazia(LISTA)){
- printf("Lista vazia!\n\n");
- return ;
- }
- node *tmp;
- tmp = LISTA->prox;
- printf("Lista:");
- while( tmp != NULL){
- printf("%5d", tmp->num);
- tmp = tmp->prox;
- }
- printf("\n ");
- int count;
- for(count=0 ; count < tam ; count++)
- printf(" ^ ");
- printf("\nOrdem:");
- for(count=0 ; count < tam ; count++)
- printf("%5d", count+1);
- printf("\n\n");
- }
- void calc(node *LISTA){
- int vet[9];
- int valor_lista, maior = 0, posi;
- node *tmp;
- tmp = LISTA->prox;
- for(int i=0; i<=9; i++){
- vet[i] = 0;
- }
- while(tmp != NULL){
- valor_lista = tmp->num;
- if (valor_lista == 0){
- vet[0]++;
- }
- else if (valor_lista == 1){
- vet[1]++;
- }
- else if (valor_lista == 2){
- vet[2]++;
- }
- else if (valor_lista == 3){
- vet[3]++;
- }
- else if (valor_lista == 4){
- vet[4]++;
- }
- else if (valor_lista == 5){
- vet[5]++;
- }
- else if (valor_lista == 6){
- vet[6]++;
- }
- else if (valor_lista == 7){
- vet[7]++;
- }
- else if (valor_lista == 8){
- vet[8]++;
- }
- else if (valor_lista == 9){
- vet[9]++;
- }
- tmp = tmp->prox;
- }
- for(int i=9; i>=0; i--){
- if (vet[i] >= maior){
- maior = vet[i];
- posi = i;
- }
- }
- printf("maior %d \n", maior);
- for(int i=0; i<=9; i++){
- if (posi == i){
- printf("%d ocorreu %d vez(es) <<<< maior ocorrencia \n",i, vet[i]);
- }else{
- printf("%d ocorreu %d vez(es) \n",i, vet[i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement