Created
June 4, 2016 00:01
-
-
Save innerspirit/ffe538ba54837ff64333d988d861fa93 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> | |
typedef struct snodo { | |
int valor; | |
struct snodo *sig; | |
} tnodo; | |
typedef tnodo *tpuntero; | |
void insertaralprincipio(tpuntero *cabeza, int dato); | |
void imprimirlista(tpuntero cabeza); | |
void borrarlista(tpuntero *cabeza); | |
int main() { | |
tpuntero cabeza; | |
int e; | |
çabeza=NULL; | |
print("Ingrese elemento -1 para terminar"); | |
scanf("%d", &e); | |
while(e!=-1) { | |
insertaralprincipio(&cabeza, e); | |
scanf("%d", &e); | |
} | |
imprimirlista(cabeza); | |
borrarlista(&cabeza); | |
return 0; | |
} | |
void insertaralprincipio(tpuntero *cabeza, int dato) { | |
tpuntero nuevo; | |
nuevo=(tpuntero) malloc(sizeof(tnodo)); | |
nuevo->valor=dato; | |
nuevo->sig=*cabeza; | |
*cabeza=nuevo; | |
} | |
void imprimirlista(tpuntero cabeza) { | |
while(cabeza!=NULL) { | |
printf("%4d", cabeza->valor); | |
cabeza=cabeza->sig; | |
} | |
} | |
void borrarlista(tpuntero *cabeza) { | |
tpuntero actual; | |
while(*cabeza!=NULL) { | |
actual=*cabeza; | |
*cabeza=(*cabeza)->sig; | |
free(actual); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment