Skip to content

Instantly share code, notes, and snippets.

@pvsousalima
Created March 1, 2013 01:58
Show Gist options
  • Save pvsousalima/5061914 to your computer and use it in GitHub Desktop.
Save pvsousalima/5061914 to your computer and use it in GitHub Desktop.
#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