Listas C++

Páginas: 13 (3035 palabras) Publicado: 3 de junio de 2012
UNIVERSIDAD DE EL SALVADOR

EISI

UNIVERSIDAD DE EL SALVADOR FACULTAD DE INGENIERIA Y ARQUITECTURA ESCUELA DE INGENIERIA DE SISTEMAS INFORMATICOS PROGRAMACION II ( SISTEMAS ) GUIA DE LABORATORIO No. 7 LISTAS, LISTAS DOBLEMENTE ENLAZADAS Y LISTAS CIRCULARES Tema: LISTAS
Objetivo: Que el estudiante a través de la práctica aprenda el funcionamiento y la utilización de las estructuras de tipolista implementada con arreglo y con memoria dinámica. Uno de los ejemplos implementa una lista de listas y en otro es necesario crear un proyecto. EJEMPLOS DE LISTAS

1. Digite, compile y ejecute el siguiente programa. #include #include #include #include #include #define NumNode 10 #define TRUE 1 #define FALSE 0 struct nodetype { char info[30]; int next; }; int getnode(struct nodetype*,int*); void insafter(int*, char*, struct nodetype *, int* ); void freenode(int p,struct nodetype *,int*); void imprimir_lista(int,struct nodetype *); int ultimo_lista(int, struct nodetype *); int isempty(int); int previo_lista(int,struct nodetype *, char *, int *); char * delafter( int, struct nodetype *, int *); char * remover( int *, struct nodetype *, int * ); char * leer_valor(void);PROGRAMACION II (SISTEMAS) 1

CICLO I/2012

UNIVERSIDAD DE EL SALVADOR

EISI

int main() { struct nodetype node[NumNode]; int avail=0; /*inicializacion de lista de nodos disponible avail a 0 */ int i, r, enc, paises=-1, herramientas=-1, alumnos=-1; char pais[30]; char herra[30]; char alum[30]; int salir=FALSE,opcion; /*inicializacion del arreglo de nodos */ for (i=0; iFinal=NULO; } intColaVacia(TipoCola q) { return((q.Frente == NULO)? CIERTO: FALSO); } void Poner(TipoDato x , TipoCola * pq) { Ptrnodoq T; T=getnode(); T->Info=x; T->Sgte=NULO; if (ColaVacia(*pq)) pq->Frente=T; else (pq->Final)->Sgte=T; pq->Final=T; } void Quitar(TipoDato * px, TipoCola * pq ) { Ptrnodoq A; if (!ColaVacia(*pq)) { *px=(pq->Frente)->Info; A=pq->Frente; pq->Frente=(pq->Frente)->Sgte; if (pq->Frente==NULO)pq->Final=NULO; freenode(A); } }

EISI

ARCHIVO LISTALIN.H #define CIERTO 1 #define FALSO 0 #define NULO 0 typedef struct{ char ISSS[10]; char Nombre[41]; int DiasTrabajados; }TipoInfo; struct Nodo{ TipoInfo Info; struct Nodo * Sgte; }; typedef struct Nodo * ApuntaNodo;
PROGRAMACION II (SISTEMAS) 9 CICLO I/2012

UNIVERSIDAD DE EL SALVADOR

EISI

void LimpiarLista(ApuntaNodo *); intListaVacia(ApuntaNodo); ApuntaNodo PostInsert(TipoInfo, ApuntaNodo ); void InserOrden(TipoInfo , ApuntaNodo *); void Suprimir(TipoInfo * , ApuntaNodo *); ARCHIVO LISTALIN.C #include "c:/instaladores/listalin.h" #include #include #include #include void LimpiarLista(ApuntaNodo * pl) { *pl=NULO; } int ListaVacia(ApuntaNodo l) { return((l == NULO)? CIERTO: FALSO); } ApuntaNodo PostInsert(TipoInfo x,ApuntaNodo l) { ApuntaNodo T; T=NULO; if (!ListaVacia(l)){ while ((strcmp(x.ISSS, l->Info.ISSS)>=0) && (l->Sgte!= NULO)){ T=l; l=l->Sgte; } if (strcmp(x.ISSS,l->Info.ISSS)>=0) T=l; } return(T); } void InserOrden(TipoInfo x , ApuntaNodo * pl) { ApuntaNodo A,N; N=(ApuntaNodo) malloc (sizeof(struct Nodo)); N->Info=x; N->Sgte=NULO; if (ListaVacia(*pl)) *pl=N; else{ A=PostInsert(x,*pl);
PROGRAMACION II(SISTEMAS) 10 CICLO I/2012

UNIVERSIDAD DE EL SALVADOR

EISI

if (A==NULO){ N->Sgte=*pl; *pl=N; } else{ N->Sgte=A->Sgte; A->Sgte=N; } } } void Suprimir(TipoInfo * px, ApuntaNodo *pl) { ApuntaNodo A; if (! ListaVacia(*pl)){ A=*pl; *px=A->Info; *pl=A->Sgte; free(A); } } ARCHIVO PROPAGA.C
/*Nombre:PROPAGA*/ #include #include #include #include #include "c:/instaladores/coladim.h" #include"c:/instaladores/listalin.h" main() { /* Variable */ TipoCola DatosDiarios; ApuntaNodo DatosGenerales, Aux; TipoDato DatoCola; TipoInfo DatoLista; FILE * arch; /* Inicializaciones */ LimpiarLista(&DatosGenerales); LimpiarCola(&DatosDiarios); arch=fopen("a:General.txt","r"); /*Creaci¢n de la lista*/ while (!feof(arch)) { fscanf(arch, "%s \n", DatoLista.ISSS); fscanf(arch, "%s \n", DatoLista.Nombre);...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Listas en c#
  • Listas en c
  • Listas c++
  • Listas en C++
  • Listas C++
  • Listas ligadas en c (dev c++)
  • Definición de un programa de listas en c
  • Lista Enlazada En C

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS