Sei sulla pagina 1di 5

#pragma once

class CEstructura
{
//Atributos
int dato;
int M, N;
int *arreglo;
bool I;
bool vacia;
public:
CEstructura();
~CEstructura();
//Metodos
public:
void crear();
bool probar();
int ver(int);
void insertar(int,int);
void eliminar(int,int);
void destruir(int,int);

void setM(int);
};

___________________________________________________________________________
void CEstructura::eliminar(int k , int dato)
{

int cont = k;
if (k < N)
{
dato = arreglo[k];
while (cont < N)
{
arreglo[cont] = arreglo[cont + 1];
cont++;
}
I = true;
N=N-1;
}
else
{
I = false;
}
}
void CEstructura::destruir(int k,int dato)
{
while (N > 0)
{
int cont = k;
if (k < N)
{
dato = arreglo[k];
while (cont < N)
{
arreglo[cont] = arreglo[cont + 1];
cont++;
}
N = true;
N = N - 1;
}
else
{
I = false;
}
}
N - 1;
}
______________________________________________________________________________
#include <iostream>
#include "CEstructura.h"
#include "CPila.h"
using namespace std;

int main() {
CPila objeto2;
CEstructura lista;
int op = 1;
int tama = 0;
int dat = 0;
int pos = 0;

while (op < 10)


{
//menu secuencial
cout << "-------LISTA SECUENCIAL------\n"
<< "Elija una accion que desee realizar \n"
<< "1. Crear lista \n"
<< "2. Probar lista \n"
<< "3. Ver lista \n"
<< "4. Insertar lista \n"
<< "5. Eliminar lista \n"
<< "6. Destruir lista \n"
<< "7. probar(crear) \n"
<< "8. probar(insert) \n"
<< "9. probar(probar) \n"
<< "10. Salir \n";

cin >> op;


switch (op) {
case 1:
cout << "Tama�o de la lista\n";
cin >> tama;
lista.setM(tama);
lista.crear();
break;
case 2:
if (lista.probar()==true)
{
cout << "Creada\n";
}
else
{
cout << "No creada";
}
break;
case 3:
cout << "Ingrese posicion para ver \n";
cin >> pos;
lista.ver(pos);
cout << "dato :" << lista.ver(pos) << endl;

break;
case 4:
cout << "ingrese posicion\n";
cin >> pos;
cout << "Ingrese datos\n";
cin >> dat;
lista.insertar(pos, dat);
break;
case 5:

break;
case 6:
break;
case 7:

break;
case 8:

break;
case 9:

break;
}
system("pause");

}
return 0;
}
___________________________________________________________________________________
__________
#include "CPila.h"
#include <iostream>
using namespace std;
bool vaciap = true;
int datopila;
CPila::CPila()
{
}

CPila::~CPila()
{
}
void CPila::crear()
{
cin >> m;
pila = new int[m];
tope=0;
base = 0;
}
bool CPila::probar()
{
if (tope == 0 && base ==0)
{
vaciap= true;
cout << "lista creada";
}
else
{
vaciap = false;

}
return vaciap;
}
void CPila::ver()
{
cout << "El ultimo dato ingresado es " << tope << endl;
}
void CPila::insertar()
{
cout << "Ingrese dato\n";
cin >> datopila;
int j;
if (tope < m)
{
i = true;
if (tope <= tope + 1)
{
j = tope;
while (j > tope) {
pila[j + 1] = pila[j];
j = j - 1;
}
pila[tope] = datopila;
tope = tope + 1;
}
else {
i = false;
}
}
}
___________________________________________________________________________________
__________
#pragma once
class CPila
{
//Atributos
int m, tope = -1;
int base = -1;
int *pila;
bool i;
public:
CPila();
~CPila();
//Metodos
public:
void crear();
bool probar();
void ver();
void insertar();
void eliminar();
void destruir();
};

Potrebbero piacerti anche