Created
December 8, 2022 19:25
-
-
Save Samu31Nd/86d3d07230630a5d82427012792da3db to your computer and use it in GitHub Desktop.
Colas Dinamicas [NODOS]
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
| // Archivo de colaDina.c | |
| #include "ColaDina.h" | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| // CREACION DE UNA COLA VAC�A | |
| COLA crearCola ( ){ | |
| COLA C; | |
| C = (COLA)malloc(sizeof(Cola)); | |
| if( C == NULL){ | |
| manejaError(0); | |
| exit(0); | |
| } | |
| C->primero = NULL; | |
| C->ultimo = NULL; | |
| return C; | |
| } | |
| // CREA UN ELEMENTO DE LA COLA | |
| Nodo_Cola * crearNodoCola( ){ | |
| Nodo_Cola * nvo; | |
| nvo = (Nodo_Cola *)malloc(sizeof(Nodo_Cola)); | |
| if( nvo == NULL){ | |
| manejaError(0); | |
| exit(0); | |
| } | |
| return nvo; | |
| } | |
| // ESTA VAC�A LA COLA | |
| int es_vaciaCola (COLA C){ | |
| if( C-> primero == NULL && C-> ultimo == NULL) | |
| return TRUE; | |
| else | |
| return FALSE; | |
| } | |
| // CONSULTAR EL PRIMER ELEMENTO DE LA ESTRUCTURA COLA | |
| int primero (COLA C){ | |
| int v; | |
| if( es_vaciaCola(C)==TRUE){ | |
| manejaError(4); //COLA VACIA | |
| exit(0); | |
| } | |
| v = C -> primero -> dato; | |
| return v; | |
| } | |
| // AGREGAR ELEMENTOS A LA COLA | |
| void encolar (COLA C, int e){ | |
| Nodo_Cola * nvo; | |
| nvo = crearNodoCola( ); | |
| nvo -> dato = e; | |
| nvo -> siguiente = NULL; | |
| if ( es_vaciaCola(C)==TRUE){ | |
| C -> primero = nvo; | |
| C -> ultimo = nvo; | |
| } | |
| else{ | |
| C ->ultimo ->siguiente = nvo; | |
| C -> ultimo = nvo; | |
| } | |
| C -> ultimo = nvo; | |
| } | |
| // ELIMINAR UN ELEMENTO DE LA COLA | |
| int desencolar(COLA C){ | |
| int v; | |
| Nodo_Cola * aux; | |
| if( es_vaciaCola(C)==TRUE){ | |
| manejaError(4); //COLA VACIA | |
| exit(0); | |
| } | |
| aux = C -> primero; | |
| v = aux -> dato; | |
| C-> primero = aux ->siguiente; | |
| if ( C-> primero == NULL) | |
| C -> ultimo = NULL; | |
| free(aux); | |
| return v; | |
| } |
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
| //Archivo colaDina.h | |
| #ifndef colaDina | |
| #define colaDina | |
| #define TRUE 1 | |
| #define FALSE 0 | |
| typedef struct Nodo_Cola{ | |
| int dato; | |
| struct Nodo_Cola * siguiente; | |
| }Nodo_Cola; | |
| typedef struct{ | |
| Nodo_Cola * primero; | |
| Nodo_Cola * ultimo; | |
| }Cola; | |
| typedef Cola * COLA; | |
| //FALTAN LOS PROTOTIPOS DE LAS | |
| // OPERACIONES DE LA COLA | |
| COLA crearCola(); | |
| Nodo_Cola *crearNodoCola(); | |
| int es_vaciaCola (COLA); | |
| int primero (COLA); | |
| void encolar (COLA, int); | |
| int desencolar(COLA); | |
| #endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment