You are on page 1of 8

#include

#include
#include
#include

<stdio.h>
<ncurses.h>
<stdlib.h>
<iostream>

typedef struct nodo {


int dato;
struct nodo * sig;
} NODO;
typedef NODO * PTRNODO;
void Insertar (PTRNODO * inicio, int Elemento) {
PTRNODO anterior, real, nuevo;
nuevo = (NODO *) malloc ( sizeof (NODO));
si (nuevo! = NULL) {
Nuevo-> dato = Elemento;
Nuevo-> sig = NULL;
anterior = NULL;
real = * inicio;
mientras que (real! = NULL && Elemento> actual-> dato) {
anterior = real;
real = actual-> sig;
}
si (anterior == NULL) { // si es el inicio
Nuevo-> sig = * inicio;
* Inicio = nuevo;
}
otra cosa {
antero> sig = nuevo;
Nuevo-> sig = real;
}
}
otra cosa printf ( "No hay memoria" );
}
int ELIMINAR (PTRNODO * inicio, int Elemento) {
PTRNODO anterior, real, temperatura;
si (Elemento == (* inicio) -> dato) { // Si Es El Primero
temp = * inicio;
* Inicio = (* inicio) -> sig;
libre (temperatura);
volver Elemento;
}
otra cosa {
anterior * = inicio;
real = (* inicio) -> sig;
mientras que (real! = NULL && actual-> dato! = Elemento) {
anterior = real;
real = actual-> sig;
}
si (real! = NULL) {
temp = real;
antero> sig = actual-> sig;
libre (temperatura);
retorno (Elemento);
}
otra vuelta (-1);
}

}
void imprimir (PTRNODO inicio) {
printf ( "La Lista es:" );
mientras (inicio! = NULL) {
printf ( "% d" , inicio-> dato);
inicio = inicio-> sig;
}
printf ( "\ n" );
}
vaco main_lista () {
PTRNODO inicio = NULL;
Char opcion;
int opc;
int Elemento;
hacer {
printf ( "\ n (1) Insertar \ n (2) ELIMINAR \ n (3) Imprimir \ n (4)
Salir \ n" );
printf ( "\ nSeleccion:" );
scanf ( "% d" , y OPC);
interruptor (opc) {
caso 1:
int qr;
printf ( "Cuantos Elementos DESEA buscas? Busca otros?"
);
scanf ( "% d" , y qr);
para ( int i = 0; i <qr; i ++) {
printf ( "Elemento Ingrese:" );
scanf ( "% d" , y Elemento);
Insertar (y inicio, Elemento);
}
romper ;
caso 2:
si (inicio == NULL) { printf ( "\ n \ nNO HAY ELEMENTOS
!!!! \ n" );
// Romper;
// Goto etiqueta_1;
} otro {
printf ( "Elemento Ingrese:" );
scanf ( "% d" , y Elemento);
Elemento = ELIMINAR (y inicio, Elemento);
si (Elemento == - 1) { printf ( "NO EXISTE EL
ELEMENTO !!!! \ n" );
}
}
romper ;
caso 3:
si (inicio == NULL) { printf ( "No Elementos heno \ n" );
} otro {
imprimir (inicio);

}
romper ;
caso 4:
/// EXIT_SUCCESS;
romper ;
}
} mientras que (opc <4);
}
</ Iostream> </ stdlib.h> </ ncurses.h> </ stdio.h>

#include <stdio.h>
#include <ncurses.h>
#include <iostream>

utilizando el espacio de nombres std;


vaco colitas_main () {
// Int main (int argc, char * argv []) {
int
int
int
int
int

tam;
Arreglo [tam];
numero, i = 0, x = 0;
borrado;
top = 0;

hacer
{
sistema ( "clear" );
printf
printf
printf
printf
printf
printf

(
(
(
(
(
(

"\
"\
"\
"\
"\
"\

n \ tCOLAS \ n \ n" );
t1 INSERTARn." );
t2 ELIMINARn." );
t3 MOSTRARn." );
t4 SALIRn." );
tQUE DESEA REALIZAR:" );

scanf ( "% i" , y numero);


interruptor (numero)
{
caso 1:
cout << "buscas? Busca otros Cuantos Datos DESEA?" ;
cin >> tam;
para ( int i = 0; i <tam; i ++) {
cout << "ingresa dato" << i << ": =" "" ; = "" cin = ""
>> Arreglo [i];
superior ++;
}
romper ;
caso 2:
int i;
si (== superior 0) {
printf ( "No exiten Datos Que ELIMINAR" );
romper ;
}
si (arriba! = 0) {
cout << "Cuantos Datos DESEA ELIMINAR?" ;
cin >> borrar;
para ( int i = 0; i <borro; i ++) {
Arreglo [i] = 0;
}
} otro {
printf ( "NO HAY DATOS EN EL ARSENAL !." ); }
romper ;
caso 3:
si (arriba! = 0) {
/// Mostrar DATOS !!!
para ( int i = 0; i <tam; i ++) {
si (Arreglo [i]! = 0) {
cout << "array [" << Arreglo [i] << "] \ n" ;
}
}
}
si (== superior 0) {
printf ( "NO HAY DATOS EN EL ARSENAL !." );
}
romper ;
caso 4:
romper ;
}
}
mientras (numero <4);
}
</ I << "> </ iostream> </ ncurses.h> </ stdio.h>

/
*
*
*
*
*

*
C ++ - Pilas / Pila
Derechos de Autor 2014 Martin Cruz Otiniano
Descripcin: Apila Elemento, Desempila Elemento, Mostrar pila, Destruir Pila
Sitio: www.marcsdev.com
/

# incluir < iostream >


utilizando el espacio de nombres

std ;

struct nodo {
int nro;
struct nodo * sgte;
};
typedef nodo * ptrPila;

// Creando nodo tipo puntero (tipo de dato)

/ * Apilar Elemento
-------------------------------------------------- ---------------------- * /
vaco empuje (ptrPila & p, int valor)
{
aux ptrPila;
aux = nuevo ( struct nodo );
// apuntamos al nuevo nodo CREADO
aux-> nro = valor;
aux-> sgte = p;
p = aux;
}
/ * Desapilar Elemento (Elemento devuelve)
-------------------------------------------------- ---------------------- * /
int pop (ptrPila & p)
{
int num;
aux ptrPila;
aux = p;
num = aux-> nro;
p = aux-> sgte;
eliminar (aux);
volver num;

// asignamos el cebador vamor de la Pila

}
/ * Muestra Elementos de la Pila
-------------------------------------------------- ---------------------- * /
vaco mostrar_pila (ptrPila p)
{
aux ptrPila;
aux = p;
// Apunta al inicio de la Lista
mientras (aux! = NULL )
{
cout << " \ t " << aux-> nro << endl;
aux = aux-> sgte;
}
}
/ * ELIMINAR TODOS LOS Elementos de la Pila
-------------------------------------------------- ---------------------- * /
vaco destruir_pila (ptrPila & p)
{
aux ptrPila;
mientras que (p! = NULL )
{
aux = p;
p = aux-> sgte;
eliminar (aux);
}
}
/ * Men de OPCIONES
-------------------------------------------------- ---------------------- * /
void men ()
{
cout << " \ n \ t IMPLEMENTACION DE PILAS EN C ++ \ n \ n " ;
cout << " 1. apilar
" << endl;
cout << " 2. DESAPILAR
" << endl;
cout << " 3. Mostrar PILA
" << endl;
cout << " 4. Destruir PILA
" << endl;
cout << " 5. SALIR
" << endl;
cout << " \ n Ingrese OPCION: " ;
}
/ * Funcion Principal
-------------------------------------------------- ---------------------- * /
int principal ()
{
ptrPila p = NULL ;
// pila Creando
int dato;
int op;

int x; // numero Que devuelve la funcon pop


sistema ( " 0b de color " );
hacer
{
Men (); cin >> op;
interruptor (op)
{
caso 1 :
cout << " \ n NUMERO A apilar: " ; cin >> dato;
empuje (p, dato);
cout << " \ n \ n \ t \ t Numero " << dato << " apilado ... \ n
\ n " ;
romper ;

caso

2 :
x = pop (p);
cout << " \ n \ n \ t \ t Numero " << x << " desapilado ... \ n

\ n " ;
romper ;

caso

3 :

cout << " \ n \ n Mostrando PILA \ n \ n " ;


si (p! = NULL )
mostrar_pila (p);
ms
cout << " \ n \ n \ t Pila vacia ..! " << endl;
romper ;

caso

4 :

destruir_pila (p);
cout << " \ n \ n \ t \ t Pila eliminada ... \ n \ n " ;
romper ;
}
cout << endl << endl;
sistema ( " pausa " );
} mientras que (op =! 5 );

sistema ( " cls " );

volver
}

0 ;

You might also like