Escolar Documentos
Profissional Documentos
Cultura Documentos
TRUJILLO- PER
2016
EJERCICIO N* 01
// DISEO DEL FORMULARIO
Imports WindowsApplication1.ClsNodo
Public Class ClsOperaLista
Public CAB As Integer
Public xLib As Integer
Public anterior As Integer
Public Sub inicializarLista(L() As ClsNodo, t As Integer)
CAB = 99
xLib = 1
anterior = 99
For k = 1 To t
L(k).dato = ""
L(k).enlace = k + 1
Next
L(t).enlace = 99
End Sub
Public Function Reservar(L() As ClsNodo) As Integer
Dim aux As Integer
If xLib = 99 Then
aux = 99
Else
aux = xLib
xLib = L(xLib).enlace
End If
Return aux
End Function
Public Sub InsertarElementos(L() As ClsNodo, xDato As String)
Dim aux2 As Integer = Reservar(L)
If aux2 <> 99 Then
L(aux2).dato = xDato
If anterior = 99 Then
L(aux2).enlace = 99
CAB = aux2
Else
L(aux2).enlace = L(anterior).enlace
L(anterior).enlace = aux2
End If
anterior = aux2
Else
MsgBox("Lista Llena ")
End If
End Sub
Public Sub Ordenar(L() As ClsNodo, t As Integer)
Dim i As Integer = 1
Dim j As Integer
Dim aux As String
While i < t
j=i+1
While j <= t
If (L(i).dato > L(j).dato) Then
aux = L(j).dato
L(j).dato = L(i).dato
L(i).dato = aux
End If
j += 1
End While
i += 1
End While
End Sub
End ClasS
DIESO DE LOS BOTONES
Imports WindowsApplication1.ClsNodo
Imports WindowsApplication1.ClsOperaLista
Public Class Form1
Public obj As New ClsOperaLista
Public L() As ClsNodo
Private Sub BtnInicializar_Click(sender As Object, e As EventArgs) Handles
BtnInicializar.Click
ReDim L(TxtTamao.Text)
obj.inicializarLista(L, TxtTamao.Text)
End Sub
Private Sub BtnRegistrar_Click(sender As Object, e As EventArgs) Handles
BtnRegistrar.Click
obj.InsertarElementos(L, TxtElemento.Text)
TxtElemento.Text = ""
TxtElemento.Focus()
End Sub
Private Sub BtnMostrar_Click(sender As Object, e As EventArgs) Handles BtnMostrar.Click
obj.Ordenar(L, TxtTamao.Text)
ListBox1.Items.Clear()
Dim pos As Integer
pos = obj.CAB
Dim xFila As String = ""
While pos <> 99
xFila = CStr(pos) + " " + L(pos).dato + " " + CStr(L(pos).enlace)
ListBox1.Items.Add(xFila)
pos = L(pos).enlace
End While
End Sub
End Class
// IMPLEMENTACION DE LOS BOTONES
Imports WindowsApplication1.ClsNodo
Imports WindowsApplication1.ClsOperaLista
Public Class Form1
Public obj As New ClsOperaLista
Public L() As ClsNodo
Private Sub BtnInicializar_Click(sender As Object, e As EventArgs) Handles
BtnInicializar.Click
ReDim L(TxtTamao.Text)
obj.inicializarLista(L, TxtTamao.Text)
End Sub
Private Sub BtnRegistrar_Click(sender As Object, e As EventArgs) Handles
BtnRegistrar.Click
obj.InsertarElementos(L, TxtElemento.Text)
TxtElemento.Text = ""
TxtElemento.Focus()
End Sub
Private Sub BtnMostrar_Click(sender As Object, e As EventArgs) Handles BtnMostrar.Click
obj.Ordenar(L, TxtTamao.Text)
ListBox1.Items.Clear()
Dim pos As Integer
pos = obj.CAB
Dim xFila As String = ""
While pos <> 99
xFila = CStr(pos) + " " + L(pos).dato + " " + CStr(L(pos).enlace)
ListBox1.Items.Add(xFila)
pos = L(pos).enlace
End While
End Sub
End Class
EJERCICIO N* 2
Else
aux = xLib
xLib = L(xLib).enlace
End If
Return aux
End Function
Public Sub InsertarElementos(L() As ClsNodo, xDato As String)
Dim aux2 As Integer = Reservar(L)
If aux2 <> 99 Then
L(aux2).dato = xDato
If anterior = 99 Then
L(aux2).enlace = 99
CAB = aux2
Else
L(aux2).enlace = L(anterior).enlace
L(anterior).enlace = aux2
End If
anterior = aux2
Else
MsgBox("Lista Llena ")
End If
End Sub
Public Sub Ordenar(L() As ClsNodo, t As Integer)
Dim i As Integer = 1
Dim j As Integer
Dim aux As String
While i < t
j=i+1
While j <= t
If (L(i).dato < L(j).dato) Then
aux = L(j).dato
L(j).dato = L(i).dato
L(i).dato = aux
End If
j += 1
End While
i += 1
End While
End Sub
End Class
// IMPLEMENTACION DE LOS BOTONES
Imports WindowsApplication1.ClsNodo
Imports WindowsApplication1.ClsOperaLista
Public Class Form1
Public obj As New ClsOperaLista
Public L() As ClsNodo
Private Sub BtnInicializar_Click(sender As Object, e As EventArgs) Handles
BtnInicializar.Click
ReDim L(TxtTamao.Text)
obj.inicializarLista(L, TxtTamao.Text)
End Sub
Private Sub BtnRegistrar_Click(sender As Object, e As EventArgs) Handles
BtnRegistrar.Click
obj.InsertarElementos(L, TxtElemento.Text)
TxtElemento.Text = ""
TxtElemento.Focus()
End Sub
Private Sub BtnMostrar_Click(sender As Object, e As EventArgs) Handles BtnMostrar.Click
ListBox1.Items.Clear()
Dim pos As Integer
pos = obj.CAB
Dim xFila As String = ""
While pos <> 99
xFila = CStr(pos) + " " + L(pos).dato + " " + CStr(L(pos).enlace)
ListBox1.Items.Add(xFila)
pos = L(pos).enlace
End While
End Sub
Private Sub ListBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles
ListBox2.SelectedIndexChanged
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs)
ListBox2.Items.Clear()
Dim pos As Integer
pos = obj.CAB
Dim xFila As String = ""
While pos <> 99
xFila = CStr(pos) + " " + L(pos).dato + " " + CStr(L(pos).enlace)
ListBox2.Items.Add(xFila)
pos = L(pos).enlace
End While
End Sub
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles
CheckBox1.CheckedChanged
obj.Ordenar(L, TxtTamao.Text)
ListBox2.Items.Clear()
Dim pos As Integer
pos = obj.CAB
Dim xFila As String = ""
While pos <> 99
xFila = CStr(pos) + " " + L(pos).dato + " " + CStr(L(pos).enlace)
ListBox2.Items.Add(xFila)
pos = L(pos).enlace
End While
End Sub
End Class
EJERCICIO N* 04
DISEO DEL FORMULARIO
OperaLista(void)
{
}
};
void OperaLista::Inicializar(EstructuraLista L[], int &cab, int &lib)
{
cab=99;
lib=0;
for(int k=0; k<50; k++)
{
L[k].dato=' ';
L[k].puntero=k+1;
}
L[49].puntero = 99;
}
void OperaLista::Agregar(EstructuraLista L[], int &cab, int &lib, char xdato)
{
L[lib].dato = xdato;
if(cab==99)
{
cab=lib;
lib=L[lib].puntero;
L[cab].puntero=99;
}
else
{
int xptr=cab;
while(L[xptr].puntero!=99)
xptr=L[xptr].puntero;
int xlib=lib;
L[xptr].puntero=lib;
lib=L[xlib].puntero;
L[xlib].puntero=99;
}
}
int OperaLista::Buscar(EstructuraLista L[],int cab,int lib,char xdato,int xtipo)
{
//Busquedad si Xtipo
if (cab == 99)
{
return 0;
}else{
int puntero = cab;
while(puntero!=99){
if (xdato == L[puntero].dato)
{
return 1;
}else{
puntero = L[puntero].puntero;
}
}
return 0;
}
}
// IMPLEMENTACION DE LOS BOTONES
#pragma endregion
e) {
}
private: System::Void btnAgregar_Click(System::Object^ sender,
System::EventArgs^ e) {
String^ xx = txtElemento->Text;
if (xx->Length == 0 || xx->Length >1 )
{
MessageBox::Show("ERROR: INGRESE 1 ELEMENTO ");
}else{
char xdato = Convert::ToChar(xx);
if (Lista.Buscar(Lista.L, Lista.CAB, Lista.LIB, xdato,0) == 0)
{
Lista.Agregar(Lista.L, Lista.CAB, Lista.LIB, xdato);
txtElemento->Text="";
txtElemento->Focus();
}else{
MessageBox::Show("ERROR: DATO YA REGISTRADO");
}
}
}
private: System::Void btnMostrar_Click(System::Object^ sender, System::EventArgs^ e) {
lstLista->Items->Clear();
int xptr=Lista.CAB;
while(xptr!=99)
{
char xdato=Lista.L[xptr].dato;
String^ xLinea = Convert::ToString(xptr)+" "+Char::ToString(xdato)
+" "+Convert::ToString(Lista.L[xptr].puntero);
lstLista->Items->Add(xLinea);
xptr=Lista.L[xptr].puntero;
}}
private: System::Void btnSalir_Click(System::Object^ sender, System::EventArgs^ e) {
MyForm::Close();
}
private: System::Void lstLista_SelectedIndexChanged(System::Object^ sender,
System::EventArgs^ e) {
}
};}
EJERCICIO N*5 ( INCLUYE EL EJERCICIO N* 03)
// DECLARAR LAS LIBRERIAS
#include "stdafx.h"
#include <iostream>
using namespace std;
struct nodo {
int data;
nodo *sgte;
};
void recorrer(nodo *cab);
void insertarFinal(nodo **cab, int data);
void insertarInicio(nodo **pcab, int data);
void insertarEnN(nodo **pcab, int data, int n);
int contarNodos(nodo *cab);
void eliminar(nodo **pcab, nodo *n);
nodo *buscar(nodo *cab, int data);
int main() {
nodo *lista = NULL;
int op = 0;
int aux, aux2;
do{
do{
cout<<"..::LISTA ENLAZADA SIMPLE::.."<<endl;
cout<<"[1] recorrer."<<endl;
cout<<"[2] insertarFinal"<<endl;
cout<<"[3] insertarInicio"<<endl;
cout<<"[4] insertarEnN"<<endl;
cout<<"[5] eliminar"<<endl;
cout<<"[6] buscar"<<endl;
cout<<"[7] salir"<<endl;
cout<<endl;
cout<<"OPCION: ";
cin>>op;
}while(op<1 || op>7);
switch(op){
case 1:
recorrer(lista);
break;
case 2:
cout<<"Ingrese un valor: ";
cin>>aux;
insertarFinal(&lista, aux);
break;
case 3:
cout<<"Ingrese un valor: ";
cin>>aux;
insertarInicio(&lista, aux);
break;
case 4:
cout<<"Ingrese un valor: ";
cin>>aux;
cout<<"Ingrese la pocicion: ";
cin>>aux2;
insertarEnN(&lista, aux, aux2);
break;
case 5:
cout<<"Ingrese un valor: ";
cin>>aux;
eliminar(&lista, buscar(lista, aux));
break;
case 6:
cout<<"Ingrese un valor: ";
cin>>aux;
cout<<"El nodo esta en la direccion: "<<buscar(lista, aux)<<endl;
break;
}
}while(op!=7);
return 0;
}
//Funcin para recorrer una lista y mostrar la data.
void recorrer(nodo *cab){
//verifica si la lista esta vaca
if(cab == NULL){
//si esta vaca muestra este mensaje
cout<<"La lista esta vacia."<<endl;
}
else{
//si no esta vaca declara un puntero p al primer elemento de la lista
nodo *p = cab;
do{
//muestra la data del nodo referido por p
cout<<"Elemento: "<<p->data<<endl;
//asigna a p la direccin de nodo siguiente o NULL si no lo hay
p = p->sgte;
//repite el proceso mientras p sea diferente de NULL
}while(p != NULL);
cout<<"Fin del recorrido."<<endl;
}
}
insertarInicio(pcab, data);
}
//si n es igual al numero de nodos (ultima posicin) llamamos a insertarFinal()
else if(n == nNodos){
insertarFinal(pcab, data);
}
//en este caso n debe estar en la zona intermedia de la lista
else{
//declaramos un puntero p al primer elemento de la lista
nodo *p = *pcab;
//avanzamos p hasta la posicin n-1
for(int i=0; i<n-1; i++)
p = p->sgte;
//creamos el nuevo nodo e iniciamos su data
nodo *nuevo = new nodo;
nuevo->data = data;
//el campo sgte del nuevo elemento apuntara al nodo siguiente de p
nuevo->sgte = p->sgte;
//el campo sgte de p apuntara al nuevo nodo
p->sgte = nuevo;
}
}
int contarNodos(nodo *cab){
int cont = 0;
while(cab!=NULL){
cab = cab->sgte;
cont++;
}
return cont;
}
//Funcin que elimina un nodo usando como criterio de busqueda la direccion del nodo
void eliminar(nodo **pcab, nodo *n){
//valida si la lista esta vacia
if(*pcab == NULL){
cout<<"La lista esta vacia."<<endl;
}
else{
//valida si el nodo a eliminar existe
if(n != NULL){
//valida si el nodo a eliminar es el primero
if(n == *pcab){
EJERCICIO N* 06
// DISEO DEL FORMULARIO
lstDatos.Items.Add(expresion)
pos = lista(pos).puntero
End While
End Sub
Private Sub btnNumElementos_Click(sender As Object, e As EventArgs) Handles
btnNumElementos.Click
Dim aux As Integer
aux = obj.devolverTamao(lista, Val(txtTamao.Text))
txtNumElementos.Text = CStr(aux)
End Sub
End Class
EJERCICIO N* 07
public:
void Inicializar(EstructuraLista[], int&, int&);
void Agregar(EstructuraLista[], int&, int&, char);
int Buscar(EstructuraLista[], int, int, char);
void Eliminar(EstructuraLista[], int&, int&, char);
void Editar(EstructuraLista[], int, int, char, char);
void Impar(EstructuraLista[], char);
OperaLista(void)
{
}
};
void OperaLista::Inicializar(EstructuraLista L[], int &cab, int &lib)
{
cab=99;
lib=0;
for(int k=0; k<50; k++)
{
L[k].dato=' ';
L[k].puntero=k+1;
}
L[49].puntero = 99;
}
void OperaLista::Agregar(EstructuraLista L[], int &cab, int &lib, char xdato)
{
L[lib].dato = xdato;
if(cab==99)
{
cab=lib;
lib=L[lib].puntero;
L[cab].puntero=99;
}
else
{
int xptr=cab;
while(L[xptr].puntero!=99)
xptr=L[xptr].puntero;
int xlib=lib;
L[xptr].puntero=lib;
lib=L[xlib].puntero;
L[xlib].puntero=99;
}
}
int OperaLista::Buscar(EstructuraLista L[],int cab,int lib,char xdato)
{
}
void OperaLista::Eliminar(EstructuraLista L[], int &cab, int &lib, char xdato)
{
}
void OperaLista::Editar(EstructuraLista L[], int cab, int lib, char xdato, char ndato)
{
}
// IMPLEMENTACION DE LOS BOTONES
#pragma endregion
private: System::Void MyForm_Load(System::Object^ sender, System::EventArgs^
e) {
Lista.CAB=99;
Lista.LIB=0;
Lista.Inicializar(Lista.L, Lista.CAB, Lista.LIB);
}
private: System::Void btnAgregar_Click(System::Object^ sender,
System::EventArgs^ e) {
String^ xx = txtElemento->Text;
char xdato = Convert::ToChar(xx);
Lista.Agregar(Lista.L, Lista.CAB, Lista.LIB, xdato);
txtElemento->Text="";
}
private: System::Void btnMostrar_Click(System::Object^ sender, System::EventArgs^ e) {
lstLista->Items->Clear();
listLista2->Items->Clear();
int xptr=Lista.CAB;
while(xptr!=99)
{
char xdato=Lista.L[xptr].dato;
String^ xLinea = Convert::ToString(xptr)+" "+Char::ToString(xdato)
+" "+Convert::ToString(Lista.L[xptr].puntero);
if(xdato%2!=0){
String^ xLinea1 = Convert::ToString(xptr)+" "+Char::ToString(xdato)
+" "+Convert::ToString(Lista.L[xptr].puntero);
listLista2->Items->Add(xLinea1);}
lstLista->Items->Add(xLinea);
xptr=Lista.L[xptr].puntero;
}
private: System::Void btnSalir_Click(System::Object^ sender, System::EventArgs^ e) {
MyForm::Close();
}
private: System::Void lstLista_SelectedIndexChanged(System::Object^ sender,
System::EventArgs^ e) {
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
listLista2->Items->Clear();
int xptr=Lista.CAB;
while(xptr!=99)
{
char xdato=Lista.L[xptr].dato;
do{
String^ xLinea = Convert::ToString(xptr)+" "+Char::ToString(xdato)
+" "+Convert::ToString(Lista.L[xptr].puntero);
listLista2->Items->Add(xLinea);
xptr=Lista.L[xptr].puntero;}while(xdato%2==0);
}}
private: System::Void label4_Click(System::Object^ sender, System::EventArgs^ e) {
}
};
}
EJERCICIO N* 08
xPtr = L(xPtr).puntero
End While
Dim wLIB As Integer = xLIB
xLIB = L(xLIB).puntero
L(xPtr).puntero = wLIB
L(wLIB).puntero = 99
End If
End If
End Sub
Public Function Promedio(L() As clsEstructuraDato, t As Integer) As Double
Dim i As Integer
Dim suma As Integer = 0
Dim prom As Double = 0
For i = 1 To t Step 1
suma = suma + Val(L(i).dato)
Next
prom = suma / t
Return prom
End Function
Public Sub listaMayor(L() As clsEstructuraDato, ListMay() As clsEstructuraDato, t As
Integer, promed As Double)
Dim i As Integer
InicializarLista(ListMay, t)
For i = 1 To t Step 1
If L(i).dato > promed Then
AgregarDato(ListMay, L(i).dato)
End If
Next
End Sub
Public Sub eliminarnodo(L() As clsEstructuraDato, t As Integer, xnodo As Integer)
Dim xptr As Integer
xptr = L(xnodo).puntero
'Solo para evaluar primer elemento
If L(xptr).puntero = xnodo Then
L(xptr).puntero = ""
End If
While xptr <> 99
Dim auxptrsig As Integer = L(xptr).puntero
If auxptrsig <> 99 Then
If L(auxptrsig).puntero = xnodo Then
L(xptr).puntero = L(auxptrsig).puntero
L(auxptrsig).dato = " "
Exit While
End If
End If
xptr = L(xptr).puntero
End While
End Sub
End ClasS
// IMPLEMENTACION DE LOS BOTONES
Imports problema_8.clsOperaLista
Imports problema_8.clsEstructuraDato
Public Class Form1
Dim lista() As clsEstructuraDato
Dim listaMayProm() As clsEstructuraDato
Dim obj As New clsOperaLista
EJERCICIO N* 09
// DECLARAR LAS LIBRERIAS
#include <iostream>
using namespace std;
break;
case 4:
cout<<"Ingrese un valor: ";
cin>>numero;
eliminar(&final, buscar(final,numero));
break;
case 5:
recorrer(final);
break;
case 6:
cout<<"El numero de nodos es: ";cout<<contarNodos(final);
break;
case 7:
cout<<"Los impares son: ";cout<<mostrar_impares(final);
break;
case 8:
//crear_lista(&cabecera, &final);
break;
}
}while(op!=9);
return 0;
}
//-------------------------- FUNCIONES -------------------------//----------- CREAR LISTA -------------void crear_lista(nodo **cab, int dato){
///crea un nodo nuevo
nodo *nuevo = new nodo;
//inicia el campo data del nuevo nodo con la data recibida por parmetro
nuevo->dato = dato;
nuevo->sgt = *cab;
//modifica la cabecera para que apunte al nuevo nodo
//el nuevo nodo sera ahora el primero
*cab = nuevo;
}
//----------- REPORTAR -------------//Funcin para recorrer una lista y mostrar la data.
void recorrer(nodo *cab){
int i = 0;
//verifica si la lista esta vaca
if(cab == NULL){
//si esta vaca muestra este mensaje
cout<<"\n\t La lista esta vacia."<<endl;
}else{
while(cab != NULL){
cout <<' '<< i+1 <<") " << cab->dato<< endl;
cab = cab->sgt;
i++;
}
cout<<"\n\t Fin del recorrido."<<endl;
}
}
//----------- INSERTAR AL FINAL -------------void insertarFinal(nodo **cab, int data){
}
//----------- INSERTAR EN UNA POSICION -------------void insertarEnN(nodo **cab, int data, int n){
int nNodos = contarNodos(*cab);
//validamos que el ndice n este en un rango valido
if(n > nNodos || n < 0){
//si no esta, mostramos un mensaje de error
cout<<"Posicion no valida. Hay "<<nNodos<<" nodos en la lista"<<endl;
}
else if(n == 0){
crear_lista(cab, data);
}else if(n == nNodos){
insertarFinal(cab, data);
}else{
//declaramos un puntero p al primer elemento de la lista
nodo *p = *cab;
//avanzamos p hasta la posicin n-1
for(int i=0; i<n-1; i++)
p = p->sgt;
nodo *nuevo = new nodo;
nuevo->dato = data;
nuevo->sgt = p->sgt;
p->sgt = nuevo;
}
}
//----------- CONTAR CUANTOS NODOS EXISTEN -------------int contarNodos(nodo *cab){
int cont = 0;
while(cab!=NULL){
cab = cab->sgt;
cont++;
}
return cont;
}
//----------- FUNCION PARA ELIMINAR UN NODO -------------void eliminar(nodo **pcab, nodo *n){
//valida si la lista esta vacia
if(*pcab == NULL){