Sunteți pe pagina 1din 9

struct nodo * crearNodo(char nombre[20], int edad) { struct nodo * aux = (struct nodo*)malloc(sizeof(struct nodo)); aux->edad = edad; strcpy(aux->nombre,

nombre); aux->siguiente = NULL; return aux; } struct nodo * agregarPpio(struct nodo * lista, struct nodo * nuevoNodo) { if(lista == NULL) { lista = nuevoNodo; } else { nuevoNodo->siguiente = lista; lista = nuevoNodo; } return lista; } struct nodo * agregarFinal(struct nodo * lista, struct nodo * nuevoNodo) { if(lista == NULL) { lista = nuevoNodo; } else {

struct nodo * ultimo = buscarUltimo(lista); ultimo->siguiente = nuevoNodo; } return lista; } struct nodo * buscarUltimo(struct nodo * lista) { struct nodo * seg = lista; if (seg!=NULL) { while(seg->siguiente != NULL) { seg = seg->siguiente; } return seg; } } struct nodo * agregarEnOrden(struct nodo * lista, struct nodo * nuevoNodo) { if(lista == NULL) { lista = nuevoNodo; } else { if(strcmp(nuevoNodo>nombre,lista->nombre)<0) lista = agregarPpio(lista, nuevoNodo); else { struct nodo * ante = lista; struct nodo * seg = lista;

while( (seg != NULL)&&(strcmp(nuevoNodo>nombre,seg->nombre)>0) ) { ante = seg; seg = seg->siguiente; } nuevoNodo->siguiente = seg; ante->siguiente = nuevoNodo; } } return lista; } struct nodo * borrarTodaLaLista(struct nodo * lista) { struct nodo * proximo; struct nodo * seg; seg = lista; while(seg != NULL) { proximo = seg->siguiente; free(seg); seg = proximo; } return seg; }

struct nodo * SubprogramaIngresarNuevoDato( ) { int edad; char nombre[20]; struct nodo * nuevoNodo; fflush(stdin); printf("ingrese nombre: "); scanf("%s", nombre); fflush(stdin); printf("ingrese edad:"); scanf("%d", &edad); nuevoNodo = crearNodo(nombre, edad); return nuevoNodo; } void recorrerYmostrar(struct nodo * lista) { struct nodo * seg = lista; while (seg != NULL) { escribir(seg); seg= seg->siguiente; } } struct nodo * SubprogramaIngresarDatosAlFina l(struct nodo * lista) { struct nodo * nuevoNodo; char cont = 's'; while (cont=='s') { nuevoNodo = SubprogramaIngresarNuevoDato( );

lista = agregarFinal(lista, nuevoNodo); printf("desea continuar s/n: "); cont=getch(); printf("\n"); } return lista; } struct nodo * SubprogramaingresarDatosAlPpio (struct nodo * lista) { struct nodo * nuevoNodo; char cont = 's'; while (cont=='s') { nuevoNodo = SubprogramaIngresarNuevoDato( ); lista = agregarPpio(lista, nuevoNodo); printf("desea continuar s/n: "); cont=getch(); printf("\n"); } return lista; } struct nodo * SubprogramaAgregarUnNodoEnO rden(struct nodo * lista) { system("cls"); struct nodo * nuevoNodo = SubprogramaIngresarNuevoDato( ); lista = agregarEnOrden(lista, nuevoNodo);

return lista; } struct nodo * SubprogramaCrearListaOrdenada (struct nodo * lista) { system("cls"); char cont = 's'; while (cont=='s') { lista = SubprogramaAgregarUnNodoEnO rden(lista); printf("desea continuar s/n: "); cont=getch(); printf("\n"); } return lista; } void SubprogramaBusquedaDeUnNod o(struct nodo * lista) { char nombre[20]; struct nodo * nodoBuscado; printf("Ingrese nombre:"); scanf("%s",nombre); printf("\n"); nodoBuscado = buscarNodo(nombre, lista); if(nodoBuscado != NULL) escribir(nodoBuscado); else printf("No se ha encontrado ese nodo\n"); }

struct nodo * SubprogramaBorrarNodo(struct nodo * lista) { char nombre[20]; printf("ingrese un nombre para eliminarlo de la lista:"); scanf("%s",nombre); lista = borrarNodo(nombre,lista); return lista; } struct nodo * borrarprimernodo(struct nodo ** lista) { struct nodo * proximo; struct nodo * seg; seg = *lista; if(seg != NULL) { proximo = seg->siguiente; free(seg); *lista=proximo; } return *lista; } struct nodo * borrarultimo(struct nodo * lista) { struct nodo * ultimo=buscarUltimo(lista); struct nodo * ante=buscaranteultimo(lista); int cant=contarnodos(lista); if(lista != NULL) { if (cant>1) {

free(ultimo); ante->siguiente=NULL; } else { borrarprimernodo(&lista); } } return lista; } int sumarecursiva (struct nodo * lista) { int rta=0; if(lista!=NULL) { rta=lista>edad+sumarecursiva(lista>siguiente); } return rta; } void mostrarrecursiva (struct nodo* lista) { if (lista!=NULL) { printf("%s",lista->nombre); printf("\n%d\n\n",lista>edad); mostrarrecursiva (lista>siguiente); getch(); } } void mostraralreves (struct nodo* lista)

{ if (lista!=NULL) { mostrarrecursiva (lista>siguiente); printf("%s",lista->nombre); printf("\n%d\n\n",lista>edad); getch(); } } int menorde2(int uno, int dos) { int rta=uno; if(uno>dos) { rta=dos; } return rta; } int menor (struct nodo*lista) { int rta; if (lista->siguiente==NULL) { rta=lista->edad; } else { rta=menorde2(lista>edad,menor(lista->siguiente)); } return rta; }

struct nodo * invertirlistarecursiva(struct nodo * lista) { struct nodo * segundo; struct nodo * listaDos; if (lista!=NULL) { segundo=lista->siguiente; listaDos=agregarFinal(listaD os,lista); } listaDos=lista; return listaDos; } void inicpila(struct pila* p) { int *aux; aux = (int *)malloc(10*sizeof(int)); p->valores = aux; p->postope=0; } void apilar(struct pila * p, int dato) { int index = (*p).postope; (*p).valores[index]=dato; (*p).postope = (*p).postope + 1; } int desapilar(struct pila * p)

{ int z = p->valores[p>postope -1]; p->postope--; return z; } int tope(P_Pila p) { return p->valores[p>postope - 1]; } int pilavacia(P_Pila p) { return (p->postope == 0); } void leer (P_Pila p) { int aux = 0; if (p->postope < 50) { printf("Ingrese un valor entero: "); fflush(stdin); scanf("%d", &aux); apilar(p, aux); } else printf("Error: la pila esta llena"); } void mostrar(P_Pila p) { int i; printf("\nBase .......................... .................... Tope\n\n"); for(i=0; i < p->postope; i++)

printf("| %d ", p>valores[i]); printf("\n\nBase ....................... ....................... Tope\n\n"); } int factorial(int x) { int resp; if(x==0) { resp=1; } else { resp=x* factorial(x-1); } return resp; } int potencia(int numero, int exponente) { int pot=0; if (exponente == 0) { pot = 1; } else { pot = numero * potencia(numero,exponente - 1); } return pot; } void muestra(int arreglo[20], int index)

{ if (index < 20) { printf(" %d |",arreglo[index]); muestra(arreglo,index + 1); } } void muestra_invertido(int arreglo[20], int index) { if (index < 20) { muestra(arreglo,index + 1); printf(" %d |",arreglo[index]); } } int es_capicua(int arreglo[20], int izquierda, int derecha) { int capicua = 1; if ((izquierda < derecha) && (capicua != 1)) { if (arreglo[izquierda] != arreglo[derecha]) { capicua = 0; } else { es_capicua(arreglo,izquie rda + 1, derecha - 1); } } }

return capicua;

int suma(int arreglo[20], int index) { int resultado=0; if (index == 19) { resultado = arreglo[index]; } else { resultado = arreglo[index] + suma(arreglo,index + 1); } return resultado; } int pos_menor(int arreglo[20], int index) { if (index == 19) { if (arreglo[index]<arreglo[pos_men or(arreglo,index + 1)]) { return index; } } } Struct nodo2 { Int dato; Struct nodo2 *siguiente;

Struct nodo2*anterior; }; Struct Nodo2* iniclista { Return NULL; } Struct nodo2 * creardato(int dato) { Struct Nodo2 *aux=(struct nodo2*) malloc (sizeof(struct nodo2)); Aux->dato=dato; aux->anterior=NULL; aux->siguienter=NULL; return aux; } struct nodo2 * agregarp(struct nodo2 * lista, struct nodo2 * nuevo) { nuevo->siguiente=lista; if (lista != NULL) { lista -> anterior = nuevo; } return nuevo; }

{ rta = NULL; } else { if(lista->sig == NULL) { rta = lista; } else{ rta = buscarultimoR(lista>sig); } } return rta; } struct nodo2 * agregarAlFinal(struct Nodo2 * lista,struct Nodo2 * nuevoNodo) { struct nodo2 * ultimo = NULL; if (lista == NULL) { lista = nuevoNodo; } else { ultimo = buscarUltimo(lista); ultimo->ste = nuevoNodo; nuevoNodo->ante = ultimo; } return lista; } struct nodo2 * insertarNodo(struct nodo2 * lista, struct nodo2 * nuevoNodo) {

struct nodo2 * buscarultimoR(struct nodo2 * lista) { struct nodo2 * rta; if (lista == NULL)

if (lista == NULL) { lista = nuevoNodo; } else { if (nuevoNodo->dato < lista>dato) { lista = agregarp(lista, nuevoNodo); } else { struct nodo2 * seg = lista>sig; struct nodo2 * ante = lista; while ( seg!= NULL && nuevoNodo->dato > seg->dato) { ante = seg; seg = seg->sig; } ante->sig = nuevoNodo; nuevoNodo->ante = ante; nuevoNodo->sig = seg; if( seg!= NULL) { seg->ante = nuevoNodo; } } } return lista; }

S-ar putea să vă placă și