Glaas2

Listas_Dobles

Jun 11th, 2012
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.79 KB | None | 0 0
  1. // listas.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <stdlib.h>
  6. #include <stdio.h>
  7.  
  8. #define TAM_NOMBRE 50
  9.  
  10. /*******************************FICHA***********************************************/
  11. typedef struct ficha_datos
  12. {
  13.     int edad;
  14.     float peso;
  15.     char nombre[TAM_NOMBRE];
  16. }Ficha;
  17.  
  18.  
  19. void llenar_ficha(Ficha *apFicha)
  20. {
  21.       int i=0;
  22.       apFicha->edad = rand()%100;
  23.       apFicha->peso = 1+rand()%300;
  24.       for(i=0;i<rand()%TAM_NOMBRE;i++)
  25.           apFicha->nombre[i]='a'+rand()%('z'-'a'+1);
  26.       apFicha->nombre[i]='\0';
  27. }
  28.  
  29. void imprimir_ficha(Ficha *apFicha)
  30. {
  31.     int i=0;
  32.     printf("Datos de Ficha\n");
  33.     printf("Nombre: "); puts(apFicha->nombre);
  34.     printf("Edad: %d\n", apFicha->edad);
  35.     printf("Peso: %.2f\n", apFicha->peso);
  36.    
  37. }
  38. /*****************************LISTA**********************************************/
  39. typedef struct elemento_de_lista
  40. {
  41.     Ficha datos;
  42.     struct elemento_de_lista *ANT, *SIG;
  43. }Elemento;
  44.  
  45. Elemento* inicializar_lista(Elemento *lista)   // inserta un elemento en la lista vacia
  46. {
  47.      Elemento *nuevo=(Elemento *)malloc(sizeof(Elemento));
  48.  
  49.      llenar_ficha(&(nuevo->datos));
  50.      nuevo->ANT=NULL;
  51.      nuevo->SIG=NULL;
  52.      imprimir_ficha(&nuevo->datos);
  53.      return nuevo;
  54.  
  55. }
  56. /*a partir de un elemento de lista, encontrar su último elemento*/
  57. Elemento* obtener_fin(Elemento *aux)
  58. {
  59.      while(aux->SIG!=NULL)
  60.          aux=aux->SIG;
  61.      return aux;
  62.  }
  63.  
  64. /*a partir de un elemento de lista, encontrar su primer elemento*/
  65.  Elemento* obtener_ini(Elemento *aux)
  66.  {
  67.      while(aux->ANT!=NULL)
  68.          aux=aux->ANT;
  69.      return aux;
  70.  }
  71.  
  72.   insertar_medio()
  73.   {
  74.       Elemento *nuevo;
  75.  
  76.  
  77.   }
  78.  
  79.  
  80. int main()
  81. {
  82.     Ficha elemento;
  83.     llenar_ficha(&elemento);
  84.     imprimir_ficha(&elemento);
  85.     return 0;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment