Created
March 1, 2013 01:58
-
-
Save pvsousalima/5061914 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include<stdio.h> | |
| #include<stdlib.h> | |
| #include<string.h> | |
| #define N 20 | |
| typedef struct Nodo { | |
| int inteiro; | |
| struct Nodo *pProximo; | |
| } Nodo; | |
| struct Nodo *pInicio = NULL; | |
| void imprimir(struct Nodo *pNodo) { | |
| if (pNodo != NULL) { | |
| printf("Número: \n", pNodo->pProximo); | |
| } else { | |
| printf("Lista vazia.\n"); | |
| } | |
| } | |
| void push(struct Nodo *pNodo) { | |
| pNodo -> pProximo = pInicio; | |
| pInicio = pNodo; | |
| } | |
| struct Nodo* pop() { | |
| if (pInicio == NULL) { | |
| printf("Não existe nada na pilha.\n"); | |
| return NULL; | |
| } else { | |
| struct Nodo *pAux = pInicio; | |
| pInicio = pAux -> pProximo; | |
| return pAux; | |
| } | |
| } | |
| int main() { | |
| int i = 0; | |
| //int vet[N]; | |
| FILE *fp; | |
| fp = fopen("fila.txt", "r"); | |
| if (fp == NULL) { | |
| printf("Nem deu."); | |
| exit(123); | |
| } else { | |
| while (!feof(fp)) { | |
| int numero=0; | |
| fscanf(fp, "%d\n", &numero); | |
| Nodo* pNodo = malloc (sizeof(struct Nodo)); | |
| pNodo.inteiro = numero; | |
| push(pNodo); | |
| i++; | |
| } | |
| } | |
| fclose(fp); | |
| struct Nodo *pNodo = pop(); | |
| while (pNodo != NULL) { | |
| imprimir(pNodo); | |
| free(pNodo); | |
| pNodo = pop(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment