<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Leo</title>
    <description>The latest articles on DEV Community by Leo (@imnotleo).</description>
    <link>https://dev.to/imnotleo</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1316083%2F8d1265d1-9fa4-4220-b638-0fc21276fb8c.png</url>
      <title>DEV Community: Leo</title>
      <link>https://dev.to/imnotleo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/imnotleo"/>
    <language>en</language>
    <item>
      <title>Listas simplemente enlasadas</title>
      <dc:creator>Leo</dc:creator>
      <pubDate>Sun, 10 Nov 2024 22:29:57 +0000</pubDate>
      <link>https://dev.to/imnotleo/listas-simplemente-enlasadas-j56</link>
      <guid>https://dev.to/imnotleo/listas-simplemente-enlasadas-j56</guid>
      <description>&lt;p&gt;Insercción, eliminación y lectura de listas simplemente enlazadas&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo9t01tgw4j3fgccvkfmr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo9t01tgw4j3fgccvkfmr.png" alt="Image description" width="800" height="700"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;stdlib.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;iostream&amp;gt;

using namespace std;
typedef int TipoDato;
struct nodo{
            TipoDato Info;
            struct nodo *Liga;
};

typedef struct nodo *TipoLista;

void InicializarLista(TipoLista &amp;amp;P){
    P=NULL;
}

bool ListaVacia(TipoLista P){
    return (P==NULL);
}

void CrearInicio( TipoLista &amp;amp;P ){
    TipoLista Q;
    int Res;

    if ( ListaVacia(P) ) {
        P= new nodo;
        cout &amp;lt;&amp;lt; "Escriba un valor del nodo: ";
        cin &amp;gt;&amp;gt; P-&amp;gt; Info;
        P-&amp;gt;Liga=NULL;
    } else {
        Q=new nodo;
        cout &amp;lt;&amp;lt; "Escriba valor del nodo: ";
        cin &amp;gt;&amp;gt; Q -&amp;gt;Info;
        Q-&amp;gt;Liga=P;
        P=Q;
    }
    cout &amp;lt;&amp;lt; "Desea anexar mas nodos a la lista? 1=Si 2=No " &amp;lt;&amp;lt; endl;
    cin &amp;gt;&amp;gt;Res;

    while(Res==1){
        Q=new nodo;
        cout &amp;lt;&amp;lt; "Escriba valor del nodo: ";
        cin &amp;gt;&amp;gt; Q -&amp;gt;Info;
        Q-&amp;gt;Liga=P;
        P=Q;

        cout &amp;lt;&amp;lt; "Desea anexar mas nodos a la lista? 1=Si 2=No " &amp;lt;&amp;lt; endl;
        cin &amp;gt;&amp;gt;Res;
    }
}

void Recorre_iterativo(TipoLista P){

TipoLista Q=P;

while(Q!=NULL){
    cout&amp;lt;&amp;lt; Q-&amp;gt;Info &amp;lt;&amp;lt; " ";
    Q=Q-&amp;gt;Liga;
}
}

void Recorre_recursivo(TipoLista P){
if(P!=NULL){
    cout&amp;lt;&amp;lt; P-&amp;gt;Info &amp;lt;&amp;lt; " ";
    Recorre_recursivo(P-&amp;gt;Liga);
}
}

void InsertarInicio ( TipoLista &amp;amp;P, TipoDato Dato ){

    TipoLista Q;
    Q = new nodo;
    Q -&amp;gt; Info = Dato;
    Q -&amp;gt; Liga = P;
    P = Q;
}

void InsertarFinal ( TipoLista &amp;amp;P, TipoDato Dato ){

    TipoLista Q, T;

    Q = new nodo;
    Q -&amp;gt; Info = Dato;
    Q -&amp;gt; Liga = NULL;

    if ( !ListaVacia( P ) ) {

        T = P;
        while ( T -&amp;gt; Liga != NULL )
        T = T -&amp;gt; Liga;
        T -&amp;gt; Liga = Q;
    } else P = Q;
}

void InsertarAntes ( TipoLista &amp;amp;P, TipoDato Dato, TipoDato Ref ) {

    if( !ListaVacia(P) ){

        TipoLista Q = P, T;

        while( Q != NULL &amp;amp;&amp;amp; Q -&amp;gt; Info != Ref ){
            T = Q;
            Q = Q -&amp;gt; Liga;
        }

        if( Q != NULL){
            TipoLista X = new nodo;
            X-&amp;gt; Info = Dato;
            if( Q == P ){
                X-&amp;gt;Liga = P;
                P = X;
            } else{
                T-&amp;gt;Liga = X;
                X-&amp;gt;Liga = Q;
            }
        } else cout &amp;lt;&amp;lt; "\n\tLa referencia "&amp;lt;&amp;lt; Ref &amp;lt;&amp;lt; " no existe!\n" &amp;lt;&amp;lt; endl;
    } else cout &amp;lt;&amp;lt; "\n\tLista vacia, ingrese datos\n";
}


void InsertarDespues ( TipoLista &amp;amp;P, TipoDato Dato, TipoDato Ref ){


    if ( !ListaVacia(P) ){

        TipoLista Q = P;

        while ( Q != NULL &amp;amp;&amp;amp; Q -&amp;gt; Info != Ref ) Q = Q -&amp;gt; Liga;

            if ( Q -&amp;gt; Liga != NULL ){

                TipoLista X = new nodo;
                X -&amp;gt; Info = Dato;
                X -&amp;gt; Liga = Q -&amp;gt; Liga;
                Q -&amp;gt; Liga = X;
            } else cout &amp;lt;&amp;lt; "\n\tLa referencia " &amp;lt;&amp;lt; Ref &amp;lt;&amp;lt; " no existe!\n"; 
    } else cout &amp;lt;&amp;lt; "\n\tLista vacia, ingrese datos\n";
}

void EliminarInicio( TipoLista &amp;amp;P){

    if ( !ListaVacia(P) ){

        TipoLista Q = P;
        P = P -&amp;gt; Liga;
        delete Q;
    } else cout &amp;lt;&amp;lt; "\n\tLista vacia. \n";
}

void EliminarUltimo( TipoLista &amp;amp;P ){

    if ( !ListaVacia(P) ){

        if ( P -&amp;gt; Liga == NULL ) delete P;
        else {
            TipoLista Q = P, T;
            while (Q-&amp;gt;Liga != NULL){
                T = Q;
                Q = Q-&amp;gt;Liga;
            } T-&amp;gt;Liga = NULL; delete Q;
        }
    } else cout &amp;lt;&amp;lt; "\n\tLista vacia. \n";
}

void EliminarNodo( TipoLista &amp;amp;P, TipoDato X ){

    if( !ListaVacia(P) ){

        TipoLista Q = P, T;

        while ( Q != NULL &amp;amp;&amp;amp; Q -&amp;gt; Info != X ){

            T = Q;
            Q = Q -&amp;gt; Liga;
        }
            if ( Q != NULL ){

                if ( P == Q ) P = Q -&amp;gt; Liga;
                else T -&amp;gt; Liga = Q -&amp;gt; Liga;
                delete Q;
            } else cout &amp;lt;&amp;lt; "\n\tLa referencia "&amp;lt;&amp;lt; X &amp;lt;&amp;lt; " no existe!\n" &amp;lt;&amp;lt; endl;
    } else cout &amp;lt;&amp;lt; " \n\tLista vacia. \nNo existe " &amp;lt;&amp;lt; X &amp;lt;&amp;lt; endl;
}

void EliminarAntes( TipoLista &amp;amp;P, TipoDato X ){

    if( !ListaVacia(P) ){

        TipoLista Q = P, T, R;

        while( Q != NULL &amp;amp;&amp;amp; Q -&amp;gt; Info != X ){
            R = T;
            T = Q;
            Q = Q -&amp;gt; Liga;
        }

        if( Q != NULL){
            if( T != NULL ){
                if( R == NULL ) P = T-&amp;gt;Liga;
                else R-&amp;gt;Liga = T-&amp;gt;Liga;
                delete T;
            } else cout &amp;lt;&amp;lt; "\nNo existe nodo antes del nodo con la referencia " &amp;lt;&amp;lt; X &amp;lt;&amp;lt; " (es el primer nodo).\n"&amp;lt;&amp;lt; endl;
        } else cout &amp;lt;&amp;lt; "\n\tLa referencia "&amp;lt;&amp;lt; X &amp;lt;&amp;lt; " no existe!\n" &amp;lt;&amp;lt; endl;
    } else cout &amp;lt;&amp;lt; "\n\tLista vacia, ingrese datos. \n";
}

void EliminarDespues( TipoLista &amp;amp;P, TipoDato X ){

    if( !ListaVacia(P) ){

        TipoLista Q = P, T;

        while ( Q != NULL &amp;amp;&amp;amp; Q-&amp;gt;Info != X ) {
            T = Q;
            Q = Q-&amp;gt;Liga;
        }
        if( Q != NULL ){
            if( Q-&amp;gt;Liga != NULL ){
                if ( P == Q ) {
                    T = P-&amp;gt;Liga;
                    P-&amp;gt;Liga = T-&amp;gt;Liga;
                } else {
                    T = Q-&amp;gt;Liga;
                    Q -&amp;gt; Liga = T -&amp;gt; Liga;
                }
                delete T;
            } else cout &amp;lt;&amp;lt; "\n\tLa referencia " &amp;lt;&amp;lt; X &amp;lt;&amp;lt; " no tiene nodo siguiente!\n" &amp;lt;&amp;lt; endl;
        } else cout &amp;lt;&amp;lt; "\n\tLa referencia " &amp;lt;&amp;lt; X &amp;lt;&amp;lt; " no existe!\n" &amp;lt;&amp;lt; endl;
    } else cout &amp;lt;&amp;lt; "\n\tLista vacia, primero ingrese datos.\n";
}

void menuPrincipal(){

    TipoDato X, Ref, Opc;
    TipoLista P;
    InicializarLista (P);
    do {

    system ("cls");
    cout &amp;lt;&amp;lt; " \n\t&amp;gt;&amp;gt; Listas simplemente enlasadas &amp;lt;&amp;lt;" &amp;lt;&amp;lt; endl;
    cout &amp;lt;&amp;lt; "\t\tby Neftali Leobardo Vazquez Castillo\n" &amp;lt;&amp;lt; endl;
    cout &amp;lt;&amp;lt; "\t\tMenu\n" &amp;lt;&amp;lt; endl;
    cout &amp;lt;&amp;lt; "1. Introducir valores manualmente, insertando al inicio. " &amp;lt;&amp;lt; endl;
    cout &amp;lt;&amp;lt; "2. Introducir valores impares del 1 al 99 insertando al inicio." &amp;lt;&amp;lt; endl;
    cout &amp;lt;&amp;lt; "3. Introducir valores impares del 1 al 99 insertando al final.\n" &amp;lt;&amp;lt; endl;
    cout &amp;lt;&amp;lt; "4. Mostrar Arreglo Recursivo. " &amp;lt;&amp;lt; endl;
    cout &amp;lt;&amp;lt; "5. Mostrar Arreglo Iterativo. " &amp;lt;&amp;lt; endl;

    cout &amp;lt;&amp;lt; "\n6. Limpiar Lista. " &amp;lt;&amp;lt; endl;

    cout &amp;lt;&amp;lt; "\n\tInsercion\n" &amp;lt;&amp;lt; endl;
    cout &amp;lt;&amp;lt; "7. Insertar al inicio. " &amp;lt;&amp;lt; endl; 
    cout &amp;lt;&amp;lt; "8. Insertar al final. " &amp;lt;&amp;lt; endl;
    cout &amp;lt;&amp;lt; "9. Insertar antes de la referencia. " &amp;lt;&amp;lt; endl;
    cout &amp;lt;&amp;lt; "10. Insertar despues de la referencia. " &amp;lt;&amp;lt; endl;

    cout &amp;lt;&amp;lt; "\n\tEliminacion\n" &amp;lt;&amp;lt; endl;
    cout &amp;lt;&amp;lt; "11. Eliminar al inicio. " &amp;lt;&amp;lt; endl;
    cout &amp;lt;&amp;lt; "12. Eliminar al final. " &amp;lt;&amp;lt; endl;
    cout &amp;lt;&amp;lt; "13. Eliminar nodo. " &amp;lt;&amp;lt; endl;
    cout &amp;lt;&amp;lt; "14. Eliminar antes de la referencia" &amp;lt;&amp;lt; endl;
    cout &amp;lt;&amp;lt; "15. Eliminar despues de la referenccia" &amp;lt;&amp;lt; endl;

    cout &amp;lt;&amp;lt; "\n\t0. Salir" &amp;lt;&amp;lt; endl;

    cout &amp;lt;&amp;lt; "\n\tOpcion: "; cin &amp;gt;&amp;gt; Opc;

    switch(Opc){

    case 1: CrearInicio(P); break;
    case 2: for (int i=1; i&amp;lt;=100; i=i+2) InsertarInicio( P,  i);
        Recorre_recursivo(P); cout &amp;lt;&amp;lt; endl; system("pause"); break;
    case 3: for (int i=1; i&amp;lt;=100; i=i+2) InsertarFinal( P,  i);
        Recorre_recursivo(P); cout&amp;lt;&amp;lt; endl; system("pause"); break;
    case 4: Recorre_recursivo(P); cout&amp;lt;&amp;lt; endl; system("pause"); break;
    case 5: Recorre_iterativo(P); cout&amp;lt;&amp;lt; endl; system("pause"); break;
    case 6: while ( P != NULL ) EliminarInicio(P); break;
    case 7: cout&amp;lt;&amp;lt; "Ingrese dato a insertar: "; cin &amp;gt;&amp;gt; X; InsertarInicio(P, X); Recorre_recursivo(P); cout &amp;lt;&amp;lt; endl; system("pause"); break;
    case 8: cout&amp;lt;&amp;lt; "Ingrese dato a insertar: "; cin &amp;gt;&amp;gt; X; InsertarFinal(P, X); Recorre_recursivo(P); cout &amp;lt;&amp;lt; endl; system("pause"); break;
    case 9: cout&amp;lt;&amp;lt; "Ingrese dato a insertar: "; cin &amp;gt;&amp;gt; X; cout&amp;lt;&amp;lt; "Ingrese referencia: "; cin&amp;gt;&amp;gt;Ref; InsertarAntes(P, X, Ref); Recorre_recursivo(P); cout &amp;lt;&amp;lt; endl; system("pause"); break;
    case 10: cout&amp;lt;&amp;lt; "Ingrese dato a insertar: "; cin &amp;gt;&amp;gt; X; cout &amp;lt;&amp;lt; "Ingrese referencia: "; cin&amp;gt;&amp;gt;Ref; InsertarDespues(P, X, Ref); Recorre_recursivo(P); cout &amp;lt;&amp;lt; endl; system("pause"); break;
    case 11: EliminarInicio(P); Recorre_recursivo(P); cout&amp;lt;&amp;lt; endl; system("pause"); break;
    case 12: EliminarUltimo(P); Recorre_recursivo(P); cout&amp;lt;&amp;lt; endl; system("pause"); break;
    case 13: cout&amp;lt;&amp;lt; "Ingrese dato a eliminar: "; cin &amp;gt;&amp;gt; X; EliminarNodo(P, X); Recorre_recursivo(P); cout &amp;lt;&amp;lt; endl; system("pause"); break;
    case 14: cout&amp;lt;&amp;lt; "Ingrese referencia: "; cin&amp;gt;&amp;gt;X; EliminarAntes(P, X); Recorre_recursivo(P); cout &amp;lt;&amp;lt; endl; system("pause"); break;
    case 15: cout&amp;lt;&amp;lt; "Ingrese referencia: "; cin&amp;gt;&amp;gt;X; EliminarDespues(P, X); Recorre_recursivo(P); cout &amp;lt;&amp;lt; endl; system("pause"); break;

    }
    } while (Opc != 0);
    system("cls");
    cout &amp;lt;&amp;lt; "\n\n\tGracias por usar mi programa, puedes usarlo cuando gustes!\n" &amp;lt;&amp;lt; endl;
    cout &amp;lt;&amp;lt; "\t\t\t\tby ImNot Leo :D\n\n" &amp;lt;&amp;lt; endl;
}

int main()
{
    menuPrincipal();
    return 0;
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>cpp</category>
    </item>
    <item>
      <title>Métodos de Ordenación y Búsqueda</title>
      <dc:creator>Leo</dc:creator>
      <pubDate>Sun, 10 Nov 2024 22:27:51 +0000</pubDate>
      <link>https://dev.to/imnotleo/metodos-de-ordenacion-y-busqueda-45g2</link>
      <guid>https://dev.to/imnotleo/metodos-de-ordenacion-y-busqueda-45g2</guid>
      <description>&lt;p&gt;Metodos de ordenación y búsqueda&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffn5d51j35ovw4gjit0rb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffn5d51j35ovw4gjit0rb.png" alt="Image description" width="596" height="677"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;stdlib.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;iostream&amp;gt;
#include &amp;lt;time.h&amp;gt;


using namespace std;

// Constantes
#define MAX 10

// Variables
int A[ MAX ]; // Arreglo de enteros
int N = MAX; // Total de elementos

// *** Sección de Prototipos
// Funciones generales
void MenuPrincipal();
void IngresarUsuario();
void IngresarAleatorio();
void MostrarArreglo();
void MostrarTiempo( time_t Inicio, time_t Final );

// Métodos de Ordenación
void BubbleSort( int A[], int N );
void ShakerSort( int A[], int N );
void InsercionDirecta( int A[], int N );
void InsercionBinaria( int A[], int N );
void SeleccionDirecta( int A[], int N );
void Shell( int A[], int N );
void QuickSort( int A[], int Izq, int Der );
void HeapSort( int A[], int N );
void Merge( int A[], int Izq, int Der);

// Métodos de Ordenación
int BusqSec( int A[], int N, int X );
int BusqBin( int A[], int N, int X );
int Hash();


// Implementación de procedimientos y funciones de usuario generales
void IngresarUsuario()
{
  for ( int i=0; i &amp;lt; MAX; i++)
    {
      cout &amp;lt;&amp;lt; "Introduce elemento " &amp;lt;&amp;lt; i + 1 &amp;lt;&amp;lt; ": ";
      cin &amp;gt;&amp;gt; A[i];
    };
};

void IngresarAleatorio()
{
  srand(time(NULL));
  for ( int i=0; i &amp;lt; MAX; i++)
      A[i]= rand() % 999;
 };

void MostrarArreglo()
{
  for (int i=0; i&amp;lt;MAX; i++)
      cout &amp;lt;&amp;lt; A[i] &amp;lt;&amp;lt; " ";
  cout &amp;lt;&amp;lt; endl;
};

void MostrarTiempo( time_t Inicio, time_t Final )
{
  printf( "Comienzo: %u s\n", Inicio );
  printf( "Final: %u s\n", Final );
  printf( "Número de segundos transcurridos desde el comienzo del programa: %f s\n", difftime( Final, Inicio) ); 
  system("pause");
}

// Implementación de Métodos de Ordenación

// Métodos de Ordenación
void BubbleSort( int A[], int N )
{
    // Ciclo externo realiza N-1 iteraciones
    for (int i = 0; i &amp;lt; N - 1; i++)
    {
        // Ciclo interno para comparar e intercambiar si es necesario
        for (int j = 0; j &amp;lt; N - i - 1; j++)
        {
            if (A[j] &amp;gt; A[j + 1])
            {
                // Intercambio de elementos
                int AUX = A[j];
                A[j] = A[j + 1];
                A[j + 1] = AUX;
            }
        }

    }
        MostrarArreglo();
        system("pause");
}

void ShakerSort( int A[], int N )
{
    int IZQ = 1;
    int DER = N - 1;
    int K = N - 1;
    int AUX;

    do {
        // Ciclo descendente (de derecha a izquierda)
        for (int I = DER; I &amp;gt;= IZQ; I--) {
            if (A[I - 1] &amp;gt; A[I]) {
                // Intercambiar A[I-1] y A[I]
                AUX = A[I - 1];
                A[I - 1] = A[I];
                A[I] = AUX;
                K = I;
            }
        }

        IZQ = K + 1;

        // Ciclo ascendente (de izquierda a derecha)
        for (int I = IZQ; I &amp;lt;= DER; I++) {
            if (A[I - 1] &amp;gt; A[I]) {
                // Intercambiar A[I-1] y A[I]
                AUX = A[I - 1];
                A[I - 1] = A[I];
                A[I] = AUX;
                K = I;
            }
        }

        DER = K - 1;

    } while (DER &amp;gt;= IZQ); // Termina cuando los índices se crucen
    MostrarArreglo();
    system ("pause");
}

void InsercionDirecta( int A[], int N )
{
    int AUX, K;

    for (int i = 1; i &amp;lt; N; i++){
        AUX = A[i];
        K = i - 1;
        while (K &amp;gt;= 0 &amp;amp;&amp;amp; A[K] &amp;gt; AUX){
            A[K + 1] = A[K];
            K -= 1;
        }
        A[K + 1] = AUX;
    }
    MostrarArreglo();
    system ("pause");
}

void InsercionBinaria( int A[], int N )
{
    int AUX, IZQ, DER, M, J;

    for (int I = 1; I &amp;lt; N; I++) {
        AUX = A[I];  // Guardar el valor actual en AUX
        IZQ = 0;     // El límite izquierdo comienza en 0
        DER = I - 1; // El límite derecho es el índice del elemento anterior a I

        // Buscar la posición correcta con búsqueda binaria
        while (IZQ &amp;lt;= DER) {
            M = (IZQ + DER) / 2;  // Calcular la mitad

            if (AUX &amp;lt; A[M]) {
                DER = M - 1;  // Ajustar límite derecho
            } else {
                IZQ = M + 1;  // Ajustar límite izquierdo
            }
        }

        // Desplazar los elementos para hacer espacio para AUX
        for (J = I - 1; J &amp;gt;= IZQ; J--) {
            A[J + 1] = A[J];
        }

        A[IZQ] = AUX;  // Insertar AUX en la posición correcta
    }
        MostrarArreglo();
        cout &amp;lt;&amp;lt; endl;
}

void SeleccionDirecta( int A[], int N )
{
    int MENOR, K;

    // Repetir con I desde 0 hasta N-2 (ajustado para trabajar con índices en 0)
    for (int I = 0; I &amp;lt; N - 1; I++) {
        MENOR = A[I];
        K = I;

        // Repetir con J desde I+1 hasta N-1
        for (int J = I + 1; J &amp;lt; N; J++) {
            if (A[J] &amp;lt; MENOR) {
                MENOR = A[J];
                K = J;
            }
        }

        // Intercambiar A[I] y A[K] si K cambió
        if (K != I) {
            int AUX = A[I];
            A[I] = A[K];
            A[K] = AUX;
        }
    }
    MostrarArreglo();
    system ("pause");
}

void Shell( int A[], int N )
{
    int INT = N + 1;
    do {
        INT = INT / 2;
        bool BAND = true;
        while (BAND) {
            BAND = false;
            int I = 0;
            while ((I + INT) &amp;lt; N) {
                if (A[I] &amp;gt; A[I + INT]) {
                    int AUX = A[I];
                    A[I] = A[I + INT];
                    A[I + INT] = AUX;
                    BAND = true;
                }
                I++;
            }
        }
    } while (INT &amp;gt; 1);
    MostrarArreglo();
    system ("pause");
}

void QuickSort( int A[], int INI, int FIN )
{
     int IZQ = INI, DER = FIN, POS = INI;
    bool BAND = true;

    // Paso 2: Mientras (BAND = VERDADERO) Repetir
    while (BAND) {
        BAND = false;

        // 2.1 Mientras ((A[POS] ≤ A[DER]) y (POS ≠ DER)) Repetir
        while ((A[POS] &amp;lt;= A[DER]) &amp;amp;&amp;amp; (POS != DER)) {
            DER--;  // Hacer DER &amp;lt;- DER - 1
        }

        // 2.3 Si (POS ≠ DER) entonces
        if (POS != DER) {
            int AUX = A[POS];  // Hacer AUX &amp;lt;- A[POS]
            A[POS] = A[DER];   // A[POS] &amp;lt;- A[DER]
            A[DER] = AUX;      // A[DER] &amp;lt;- AUX
            POS = DER;         // POS &amp;lt;- DER

            // 2.3.1 Mientras ((A[POS] ≥ A[IZQ]) y (POS ≠ IZQ)) Repetir
            while ((A[POS] &amp;gt;= A[IZQ]) &amp;amp;&amp;amp; (POS != IZQ)) {
                IZQ++;  // Hacer IZQ &amp;lt;- IZQ + 1
            }

            // 2.3.3 Si (POS ≠ IZQ) entonces
            if (POS != IZQ) {
                BAND = true;
                AUX = A[POS];  // Hacer AUX &amp;lt;- A[POS]
                A[POS] = A[IZQ];  // A[POS] &amp;lt;- A[IZQ]
                A[IZQ] = AUX;     // A[IZQ] &amp;lt;- AUX
                POS = IZQ;        // POS &amp;lt;- IZQ
            }
        }
    }

    // Paso 6: Condiciones para llamadas recursivas
    if ((POS - 1) &amp;gt; INI) {
        QuickSort(A, INI, POS - 1);  // Llamada recursiva
    }
    if ((POS + 1) &amp;lt; FIN) {
        QuickSort(A, POS + 1, FIN);  // Llamada recursiva
    }
}

void InsertaHeap ( int A[], int N )
{
    for (int i = 1; i &amp;lt; N; i++) {
        int k = i;
        bool BAND = true;

        while (k &amp;gt; 0 &amp;amp;&amp;amp; BAND) {
            BAND = false;
            int parent = (k - 1) / 2;  // Índice del padre

            if (A[k] &amp;gt; A[parent]) {  // Comparar con el padre
                // Intercambiar A[k] con A[parent]
                int AUX = A[parent];
                A[parent] = A[k];
                A[k] = AUX;

                k = parent;
                BAND = true;
            }
        }
    }
}

void EliminaHeap ( int A[], int N )
{
    int AUX = A[0];
    A[0] = A[N - 1];
    A[N - 1] = AUX;

    N--;  // Reducir el tamaño del montón
    int k = 0;
    bool BAND = true;

    while (2 * k + 1 &amp;lt; N &amp;amp;&amp;amp; BAND) {
        BAND = false;
        int hijo_izq = 2 * k + 1;
        int hijo_der = 2 * k + 2;
        int mayor = hijo_izq;

        // Verificar si el hijo derecho es mayor que el izquierdo
        if (hijo_der &amp;lt; N &amp;amp;&amp;amp; A[hijo_der] &amp;gt; A[hijo_izq]) {
            mayor = hijo_der;
        }

        if (A[mayor] &amp;gt; A[k]) {
            // Intercambiar A[k] con A[mayor]
            AUX = A[k];
            A[k] = A[mayor];
            A[mayor] = AUX;

            k = mayor;
            BAND = true;
        }
    }
}

void HeapSort( int A[], int N )
{
    InsertaHeap ( A, N );
    for (int i = N; i &amp;gt; 1; i--) EliminaHeap ( A, i );
    MostrarArreglo();
    system("pause");
}

void intercalar(int arr[], int inicio, int medio, int fin) {
    int n1 = medio - inicio + 1;
    int n2 = fin - medio;

    int izquierda[n1], derecha[n2];

    for (int i = 0; i &amp;lt; n1; i++)
        izquierda[i] = arr[inicio + i];
    for (int j = 0; j &amp;lt; n2; j++)
        derecha[j] = arr[medio + 1 + j];

    int i = 0, j = 0, k = inicio;
    while (i &amp;lt; n1 &amp;amp;&amp;amp; j &amp;lt; n2) {
        if (izquierda[i] &amp;lt;= derecha[j]) {
            arr[k] = izquierda[i];
            i++;
        } else {
            arr[k] = derecha[j];
            j++;
        }
        k++;
    }

    while (i &amp;lt; n1) {
        arr[k] = izquierda[i];
        i++;
        k++;
    }

    while (j &amp;lt; n2) {
        arr[k] = derecha[j];
        j++;
        k++;
    }
}

void Merge( int A[], int Izq, int Der)
{
    if (Izq &amp;lt; Der) {
        int medio = Izq + (Der - Izq) / 2;

        Merge(A, Izq, medio);
        Merge(A, medio + 1, Der);

        intercalar(A, Izq, medio, Der);
    }
}


// Implementación de Métodos de Búsqueda
int BusqSec( int A[], int N, int X )
{
  int i=0;

  while ( (i&amp;lt;N) &amp;amp;&amp;amp; (A[i]!= X) ) 
    i++;

  if (i&amp;gt;=N)  
     return 0;
  else 
     return i+1;    
}

int BusqBin( int V[], int N, int X )
{

    int IZQ = 0, DER = N - 1;
    bool BAN = false;
    int CEN;

    while (IZQ &amp;lt;= DER &amp;amp;&amp;amp; !BAN) {
        CEN = IZQ + (DER - IZQ) / 2;  // Calcula posición central

        if (X == V[CEN]) {
            BAN = true;  // Elemento encontrado
        } else {
            if (X &amp;gt; V[CEN]) {
                IZQ = CEN + 1;  // Busca en la mitad derecha
            } else {
                DER = CEN - 1;  // Busca en la mitad izquierda
            }
        }
    }

    if (BAN) {
        return CEN +1;
    } else {
        return 0;
    }
}

int Hash(int A[], int N, int K)
{
    const int VACIO = -1;
    int D = K % N;  // Hacer D ← H(K), genera dirección
    int DX = D;     // Inicializar DX

    // Si ((V[DX] ≠ VACIO) y (V[DX] = K)) entonces
    if (A[DX] != VACIO &amp;amp;&amp;amp; A[DX] == K) {
        cout &amp;lt;&amp;lt; "La información está en la posición " &amp;lt;&amp;lt; D &amp;lt;&amp;lt; endl;
        return D; // Fin
    }

    // Si no
    DX = D + 1;  // Hacer DX ← D + 1
    // Mientras (DX ≠ N) y (V[DX] ≠ VACIO) y (V[DX] ≠ K) y (DX ≠ D) Repetir
    while ((DX != N) &amp;amp;&amp;amp; (A[DX] != VACIO) &amp;amp;&amp;amp; (A[DX] != K) &amp;amp;&amp;amp; (DX != D)) {
        DX = DX + 1;  // Hacer DX ← DX + 1

        // Si (DX = N + 1) entonces
        if (DX == N) {
            DX = 0;  // Hacer DX ← 1
        }
    }

    // Si ((V[DX] = VACIO) o (DX = D)) entonces
    if (A[DX] == VACIO || DX == D) {
        return 0;  // Fin
    }

    // Si no
    return DX+1; // Fin
}

void MenuPrincipal()
{ // Variables locales
  char Opc;   // Variable auxiliar Opcion
  int X, Y;
  time_t Inicio, Final;

  do {
     system("cls");
     cout &amp;lt;&amp;lt; "\n\t\t *powered by ImNotLeo :D\n" &amp;lt;&amp;lt; endl;
     cout &amp;lt;&amp;lt; "\t**** Metodos de Ordenacion y Busqueda. " &amp;lt;&amp;lt; endl;
     cout &amp;lt;&amp;lt; "1. Introducir valores Usuario. " &amp;lt;&amp;lt; endl;
     cout &amp;lt;&amp;lt; "2. Introducir valores aleatoriamente. " &amp;lt;&amp;lt; endl;
     cout &amp;lt;&amp;lt; "3. Mostrar Arreglo. " &amp;lt;&amp;lt; endl &amp;lt;&amp;lt; endl;

     cout &amp;lt;&amp;lt; "\t**** Algoritmos de Ordenacion. " &amp;lt;&amp;lt; endl;
     cout &amp;lt;&amp;lt; "4. Por Intercambio Directo (Burbuja). " &amp;lt;&amp;lt; endl;
     cout &amp;lt;&amp;lt; "5. Metodo de la Sacudida (ShakerSort). " &amp;lt;&amp;lt; endl;
     cout &amp;lt;&amp;lt; "6. Metodo de Insercion Directa. " &amp;lt;&amp;lt; endl;
     cout &amp;lt;&amp;lt; "7. Metodo de Insercion Binaria. " &amp;lt;&amp;lt; endl;
     cout &amp;lt;&amp;lt; "8. Metodo de Seleccion Directa. " &amp;lt;&amp;lt; endl;
     cout &amp;lt;&amp;lt; "9. Shell. " &amp;lt;&amp;lt; endl;
     cout &amp;lt;&amp;lt; "A. QuickSort. " &amp;lt;&amp;lt; endl;
     cout &amp;lt;&amp;lt; "B. Monticulo (HeapSort). " &amp;lt;&amp;lt; endl;
     cout &amp;lt;&amp;lt; "C. Intercalacion de archivos (Merge). " &amp;lt;&amp;lt; endl &amp;lt;&amp;lt; endl;

     cout &amp;lt;&amp;lt; "\t**** Algoritmos de Busqueda. " &amp;lt;&amp;lt; endl;
     cout &amp;lt;&amp;lt; "D. Busqueda Secuencia." &amp;lt;&amp;lt; endl;
     cout &amp;lt;&amp;lt; "E. Busqueda Binaria." &amp;lt;&amp;lt; endl;
     cout &amp;lt;&amp;lt; "F. Hash." &amp;lt;&amp;lt; endl;
     cout &amp;lt;&amp;lt; "0. Salir " &amp;lt;&amp;lt; endl &amp;lt;&amp;lt; endl;
     cout &amp;lt;&amp;lt; "Opcion: "; cin &amp;gt;&amp;gt; Opc;

     switch (Opc) {
       case '1': IngresarUsuario(); break;
       case '2': IngresarAleatorio(); break;
       case '3': MostrarArreglo(); system("Pause"); break;
       //----------------------------------------------
       case '4': cout &amp;lt;&amp;lt; "\n\tArreglo Original: "; MostrarArreglo(); cout &amp;lt;&amp;lt; endl; BubbleSort( A, N ); break;
       case '5': cout &amp;lt;&amp;lt; "\n\tArreglo Original: "; MostrarArreglo(); cout &amp;lt;&amp;lt; endl; ShakerSort( A, N ); break;
       case '6': cout &amp;lt;&amp;lt; "\n\tArreglo Original: "; MostrarArreglo(); cout &amp;lt;&amp;lt; endl; InsercionDirecta( A, N ); break;

       case '7': // Inserción Binaria 
                 Inicio= time(NULL); // Tiempo inicial o actual
                 cout &amp;lt;&amp;lt; "\n\tArreglo Original: "; MostrarArreglo(); cout &amp;lt;&amp;lt; endl; InsercionBinaria( A, N ); // Llamada al Método de Ordenación
                 Final= time(NULL);    // Tiempo final o actual

                 MostrarTiempo( Inicio, Final ); // Muestra tiempo transcurrido
                 break;

       case '8': cout &amp;lt;&amp;lt; "\n\tArreglo Original: "; MostrarArreglo(); cout &amp;lt;&amp;lt; endl; SeleccionDirecta( A, N ); break;
       case '9': cout &amp;lt;&amp;lt; "\n\tArreglo Original: "; MostrarArreglo(); cout &amp;lt;&amp;lt; endl; Shell( A, N ); break;
       case 'A': cout &amp;lt;&amp;lt; "\n\tArreglo Original: "; MostrarArreglo(); cout &amp;lt;&amp;lt; endl; QuickSort( A, 0, MAX-1 ); MostrarArreglo(); system ("pause"); break;
       case 'B': cout &amp;lt;&amp;lt; "\n\tArreglo Original: "; MostrarArreglo(); cout &amp;lt;&amp;lt; endl; HeapSort( A, N ); break;
       case 'C': cout &amp;lt;&amp;lt; "\n\tArreglo Original: "; MostrarArreglo(); cout &amp;lt;&amp;lt; endl; Merge( A, 0, MAX-1 ); MostrarArreglo(); system ("pause"); break;
       //----------------------------------------------
       case 'D': // Método de Búsqueda Secuencial
                 cout &amp;lt;&amp;lt; "Escriba valor a buscar: ";
                 cin &amp;gt;&amp;gt; X;

                 Inicio= time(NULL); // Tiempo inicial o actual
                 Y= BusqSec( A, N, X ); // llamada al Método de Busqueda
                 Final= time(NULL);    // Tiempo final o actual
                    if (Y == 0) cout &amp;lt;&amp;lt; "\n\tLa informacion no esta en el arreglo. \n";
                    else printf("\n\tLa posicion encontrada fue %i \n", Y); 
                 MostrarTiempo( Inicio, Final ); // Muestra tiempo transcurrido
                 break;      

       case 'E': // Método de Búsqueda Binaria
                 cout &amp;lt;&amp;lt; "Escriba valor a buscar: ";
                 cin &amp;gt;&amp;gt; X;
                 Merge( A, 0, MAX-1 );
                 cout &amp;lt;&amp;lt; "\n\tArreglo Original: "; MostrarArreglo();
                 Inicio= time(NULL); // Tiempo inicial o actual
                 Y= BusqBin( A, N, X ); // llamada al Método de Busqueda
                 Final= time(NULL);    // Tiempo final o actual
                    if (Y == 0) cout &amp;lt;&amp;lt; "\n\tLa informacion no esta en el arreglo. \n";
                    else printf("\n\tLa posicion encontrada fue %i \n", Y); 
                 MostrarTiempo( Inicio, Final ); // Muestra tiempo transcurrido
                 break;

       case 'F': // Método de Hash
                 cout &amp;lt;&amp;lt; "Escriba valor a buscar: ";
                 cin &amp;gt;&amp;gt; X;

                 Inicio= time(NULL); // Tiempo inicial o actual
                 Y= Hash( A, N, X ); // llamada al Método de Busqueda
                 Final= time(NULL);    // Tiempo final o actual
                    if (Y == 0) cout &amp;lt;&amp;lt; "\n\tLa informacion no esta en el arreglo. \n";
                    else printf("\n\tLa posicion encontrada fue %i \n", Y); 
                 MostrarTiempo( Inicio, Final ); // Muestra tiempo transcurrido
                 break;
     };

  } while (Opc!='0');
    system("cls");
    cout &amp;lt;&amp;lt; "\n\n\tGracias por usar mi programa, puedes usarlo cuando gustes!\n" &amp;lt;&amp;lt; endl;
    cout &amp;lt;&amp;lt; "\t\t\t\tby ImNot Leo :D\n\n" &amp;lt;&amp;lt; endl;
};

// Programa o función principal del programa
int main()
{
  MenuPrincipal();
  return 0;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>cpp</category>
      <category>datastructures</category>
    </item>
    <item>
      <title>MyCalqlator - Kotlin / Android Studio</title>
      <dc:creator>Leo</dc:creator>
      <pubDate>Mon, 04 Nov 2024 05:14:12 +0000</pubDate>
      <link>https://dev.to/imnotleo/mycalqlator-koltin-android-studio-25e1</link>
      <guid>https://dev.to/imnotleo/mycalqlator-koltin-android-studio-25e1</guid>
      <description>&lt;p&gt;Here we have my first Calculator in Android Studio&lt;/p&gt;

&lt;p&gt;Start Layout&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Famcjk7ivgqn448njoq6r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Famcjk7ivgqn448njoq6r.png" alt="Image description" width="522" height="934"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Suma &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flal1y3x47pkoh50uofqh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flal1y3x47pkoh50uofqh.png" alt="Image description" width="424" height="731"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Resultado&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh0a73b8hsby603sxd0zk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh0a73b8hsby603sxd0zk.png" alt="Image description" width="432" height="685"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Code backup&lt;/p&gt;

&lt;p&gt;buttons_layouut.xml&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;
&amp;lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"&amp;gt;

    &amp;lt;GridLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:columnCount="4"
        android:rowCount="5"&amp;gt;

        &amp;lt;Button
            android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="100dp"
            android:layout_row="0"
            android:layout_column="0"
            android:layout_columnWeight="1"
            android:layout_margin="3dp"

            android:backgroundTint="#DCB3B3"
            android:onClick="borrar"
            android:text="CA"
            android:textColor="#5D0202"
            android:textSize="34sp"
            app:strokeColor="#5D0202"
            app:strokeWidth="2px" /&amp;gt;

        &amp;lt;Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="100dp"
            android:layout_row="0"
            android:layout_column="1"
            android:layout_columnWeight="1"
            android:layout_margin="3dp"

            android:backgroundTint="#DCB3B3"
            android:onClick="borrar"
            android:text="C"
            android:textColor="#5D0202"
            android:textSize="34sp"
            app:strokeColor="#5D0202"
            app:strokeWidth="2px" /&amp;gt;

        &amp;lt;Button
            android:id="@+id/button3"
            android:layout_width="wrap_content"
            android:layout_height="100dp"
            android:layout_row="0"
            android:layout_column="2"
            android:layout_columnWeight="1"
            android:layout_margin="3dp"

            android:backgroundTint="#DCB3B3"
            android:onClick="cambiarOperador"
            android:text="%"
            android:textColor="#5D0202"
            android:textSize="34sp"
            app:strokeColor="#5D0202"
            app:strokeWidth="2px" /&amp;gt;

        &amp;lt;Button
            android:id="@+id/button4"
            android:layout_width="wrap_content"
            android:layout_height="100dp"
            android:layout_row="0"
            android:layout_column="3"
            android:layout_columnWeight="1"
            android:layout_margin="3dp"

            android:backgroundTint="#5D0202"
            android:onClick="cambiarOperador"
            android:text="÷"
            android:textSize="34sp" /&amp;gt;

        &amp;lt;Button
            android:id="@+id/button5"
            android:layout_width="wrap_content"
            android:layout_height="100dp"
            android:layout_row="1"
            android:layout_column="0"
            android:layout_columnWeight="1"
            android:layout_margin="3dp"
            android:backgroundTint="@color/white"

            android:onClick="selectNumbers"
            android:text="7"
            android:textColor="#5D0202"
            android:textSize="34sp"
            app:strokeColor="#5D0202"
            app:strokeWidth="2dp" /&amp;gt;

        &amp;lt;Button
            android:id="@+id/button6"
            android:layout_width="wrap_content"
            android:layout_height="100dp"
            android:layout_row="1"
            android:layout_column="1"
            android:layout_columnWeight="1"
            android:layout_margin="3dp"
            android:backgroundTint="@color/white"

            android:onClick="selectNumbers"
            android:text="8"
            android:textColor="#5D0202"
            android:textSize="34sp"
            app:strokeColor="#5D0202"
            app:strokeWidth="2dp" /&amp;gt;

        &amp;lt;Button
            android:id="@+id/button7"
            android:layout_width="wrap_content"
            android:layout_height="100dp"
            android:layout_row="1"
            android:layout_column="2"
            android:layout_columnWeight="1"
            android:layout_margin="3dp"
            android:backgroundTint="@color/white"

            android:onClick="selectNumbers"
            android:text="9"
            android:textColor="#5D0202"
            android:textSize="34sp"
            app:strokeColor="#5D0202"
            app:strokeWidth="2dp" /&amp;gt;

        &amp;lt;Button
            android:id="@+id/button8"
            android:layout_width="wrap_content"
            android:layout_height="100dp"
            android:layout_row="1"
            android:layout_column="3"
            android:layout_columnWeight="1"
            android:layout_margin="3dp"
            android:backgroundTint="#5D0202"

            android:onClick="cambiarOperador"
            android:text="x"
            android:textColor="@color/white"
            android:textSize="34sp"
            app:strokeColor="#5D0202"
            app:strokeWidth="2dp" /&amp;gt;

        &amp;lt;Button
            android:id="@+id/button9"
            android:layout_width="wrap_content"
            android:layout_height="100dp"
            android:layout_row="2"
            android:layout_column="0"
            android:layout_columnWeight="1"
            android:layout_margin="3dp"
            android:backgroundTint="@color/white"

            android:onClick="selectNumbers"
            android:text="4"
            android:textColor="#5D0202"
            android:textSize="34sp"
            app:strokeColor="#5D0202"
            app:strokeWidth="2dp" /&amp;gt;

        &amp;lt;Button
            android:id="@+id/button10"
            android:layout_width="wrap_content"
            android:layout_height="100dp"
            android:layout_row="2"
            android:layout_column="1"
            android:layout_columnWeight="1"
            android:layout_margin="3dp"
            android:backgroundTint="@color/white"

            android:onClick="selectNumbers"
            android:text="5"
            android:textColor="#5D0202"
            android:textSize="34sp"
            app:strokeColor="#5D0202"
            app:strokeWidth="2dp" /&amp;gt;

        &amp;lt;Button
            android:id="@+id/button11"
            android:layout_width="wrap_content"
            android:layout_height="100dp"
            android:layout_row="2"
            android:layout_column="2"
            android:layout_columnWeight="1"
            android:layout_margin="3dp"
            android:backgroundTint="@color/white"

            android:onClick="selectNumbers"
            android:text="6"
            android:textColor="#5D0202"
            android:textSize="34sp"
            app:strokeColor="#5D0202"
            app:strokeWidth="2dp" /&amp;gt;

        &amp;lt;Button
            android:id="@+id/button12"
            android:layout_width="wrap_content"
            android:layout_height="100dp"
            android:layout_row="2"
            android:layout_column="3"
            android:layout_columnWeight="1"
            android:layout_margin="3dp"
            android:backgroundTint="#5D0202"

            android:onClick="cambiarOperador"
            android:text="-"
            android:textColor="@color/white"
            android:textSize="34sp"
            app:strokeColor="#5D0202"
            app:strokeWidth="2dp" /&amp;gt;

        &amp;lt;Button
            android:id="@+id/button13"
            android:layout_width="wrap_content"
            android:layout_height="100dp"
            android:layout_row="3"
            android:layout_column="0"
            android:layout_columnWeight="1"
            android:layout_margin="3dp"
            android:backgroundTint="@color/white"

            android:onClick="selectNumbers"
            android:text="1"
            android:textColor="#5D0202"
            android:textSize="34sp"
            app:strokeColor="#5D0202"
            app:strokeWidth="2dp" /&amp;gt;

        &amp;lt;Button
            android:id="@+id/button14"
            android:layout_width="wrap_content"
            android:layout_height="100dp"
            android:layout_row="3"
            android:layout_column="1"
            android:layout_columnWeight="1"
            android:layout_margin="3dp"
            android:backgroundTint="@color/white"

            android:onClick="selectNumbers"
            android:text="2"
            android:textColor="#5D0202"
            android:textSize="34sp"
            app:strokeColor="#5D0202"
            app:strokeWidth="2dp" /&amp;gt;

        &amp;lt;Button
            android:id="@+id/button15"
            android:layout_width="wrap_content"
            android:layout_height="100dp"
            android:layout_row="3"
            android:layout_column="2"
            android:layout_columnWeight="1"
            android:layout_margin="3dp"
            android:backgroundTint="@color/white"

            android:onClick="selectNumbers"
            android:text="3"
            android:textColor="#5D0202"
            android:textSize="34sp"
            app:strokeColor="#5D0202"
            app:strokeWidth="2dp" /&amp;gt;

        &amp;lt;Button
            android:id="@+id/button16"
            android:layout_width="wrap_content"
            android:layout_height="100dp"
            android:layout_row="3"
            android:layout_column="3"
            android:layout_columnWeight="1"
            android:layout_margin="3dp"
            android:backgroundTint="#5D0202"

            android:onClick="cambiarOperador"
            android:text="+"
            android:textColor="@color/white"
            android:textSize="34sp"
            app:strokeColor="#5D0202"
            app:strokeWidth="2dp" /&amp;gt;

        &amp;lt;Button
            android:id="@+id/button17"
            android:layout_width="wrap_content"
            android:layout_height="100dp"
            android:layout_row="4"
            android:layout_column="0"
            android:layout_columnSpan="2"
            android:layout_columnWeight="1"
            android:layout_margin="3dp"

            android:backgroundTint="@color/white"
            android:onClick="selectNumbers"
            android:text="0"
            android:textAlignment="viewStart"
            android:textColor="#5D0202"
            android:textSize="34sp"
            app:strokeColor="#5D0202"
            app:strokeWidth="2dp" /&amp;gt;

        &amp;lt;Button
            android:id="@+id/button18"
            android:layout_width="wrap_content"
            android:layout_height="100dp"
            android:layout_row="4"
            android:layout_column="2"
            android:layout_columnWeight="1"
            android:layout_margin="3dp"
            android:backgroundTint="@color/white"

            android:onClick="selectNumbers"
            android:text="."
            android:textColor="#5D0202"
            android:textSize="34sp"
            app:strokeColor="#5D0202"
            app:strokeWidth="2dp" /&amp;gt;

        &amp;lt;Button
            android:id="@+id/button20"
            android:layout_width="wrap_content"
            android:layout_height="100dp"
            android:layout_row="4"
            android:layout_column="3"
            android:layout_columnWeight="1"
            android:layout_margin="3dp"

            android:backgroundTint="#5D0202"
            android:onClick="igual"
            android:text="="
            android:textColor="@color/white"
            android:textSize="34sp"
            app:strokeColor="#5D0202"
            app:strokeWidth="2dp" /&amp;gt;

    &amp;lt;/GridLayout&amp;gt;
&amp;lt;/LinearLayout&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;activity_main.xml&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;
&amp;lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity"&amp;gt;

    &amp;lt;TextView
        android:id="@+id/txtTemp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:textAlignment="textEnd"
        android:textColor="#7B090000"
        android:textSize="34dp" /&amp;gt;

    &amp;lt;TextView
        android:id="@+id/txtResult"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:textAlignment="textEnd"
        android:textSize="60sp" /&amp;gt;

    &amp;lt;include
        layout="@layout/buttons_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" /&amp;gt;
&amp;lt;/LinearLayout&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;MainActivity.kt&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package com.example.mycalqlator

import android.icu.text.DecimalFormat
import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.TextView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class MainActivity : AppCompatActivity() {

    val SUMA = "+"
    val RESTA = "-"
    val MULTIPLICACION = "*"
    val DIVISION = "/"
    val PORCENTAJE = "%"

    var OpActual = ""

    var primerNumero:Double = Double.NaN
    var segundoNumero:Double = Double.NaN

    lateinit var txtTemp:TextView
    lateinit var txtResult:TextView

    lateinit var formatoDecimal: DecimalFormat

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets -&amp;gt;
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }

        formatoDecimal = DecimalFormat("#.#########")
        txtTemp = findViewById(R.id.txtTemp)
        txtResult = findViewById(R.id.txtResult)
    }

    fun cambiarOperador(b: View){
        if(txtTemp.text.isNotEmpty() || primerNumero.toString()!="NaN") {
            calqlar()
            val boton: Button = b as Button
            if (boton.text.toString().trim() == "÷") {
                OpActual = "/"
            } else if (boton.text.toString().trim() == "x") {
                OpActual = "*"
            } else {
                OpActual = boton.text.toString().trim()
            }
            txtResult.text = formatoDecimal.format(primerNumero) + OpActual
            txtTemp.text = ""
        }
    }

    fun calqlar(){
        try {
            if (primerNumero.toString() != "NaN") {
                if (txtTemp.text.toString().isEmpty()) {
                    txtTemp.text = txtResult.text.toString()
                }
                segundoNumero = txtTemp.text.toString().toDouble()
                txtTemp.text = ""

                when (OpActual) {
                    "+" -&amp;gt; primerNumero = (primerNumero + segundoNumero)
                    "-" -&amp;gt; primerNumero = (primerNumero - segundoNumero)
                    "*" -&amp;gt; primerNumero = (primerNumero * segundoNumero)
                    "/" -&amp;gt; primerNumero = (primerNumero / segundoNumero)
                    "%" -&amp;gt; primerNumero = (primerNumero % segundoNumero)
                }
            } else {
                primerNumero = txtTemp.text.toString().toDouble()
            }
        }catch (e:Exception){

        }
    }

    fun selectNumbers(b: View) {
        val boton: Button = b as Button
        val buttonText = boton.text.toString()
        val currentText = txtTemp.text.toString()

        when {
            buttonText == "." -&amp;gt; {
                if (currentText.contains(".")) return
                txtTemp.text = if (currentText.isEmpty()) "0." else currentText + "."
            }
            currentText == "0" -&amp;gt; {
                if (buttonText != "0") {
                    txtTemp.text = buttonText
                }
            }
            else -&amp;gt; {
                txtTemp.text = currentText + buttonText
            }
        }
    }


    fun igual(b: View){
        calqlar()
        txtResult.text = formatoDecimal.format(primerNumero)
        OpActual = ""
    }

    fun borrar(b:View){
        val boton:Button = b as Button
        if(boton.text.toString().trim()=="C"){
            if(txtTemp.text.toString().isNotEmpty()){
                var datosActuales:CharSequence = txtTemp.text as CharSequence
                txtTemp.text = datosActuales.subSequence(0, datosActuales.length - 1)

            }else{
                primerNumero = Double.NaN
                segundoNumero = Double.NaN
                txtTemp.text = ""
                txtResult.text = ""
            }
        }else if(boton.text.toString().trim() == "CA"){
            primerNumero = Double.NaN
            segundoNumero = Double.NaN
            txtTemp.text = ""
            txtResult.text = ""
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>kotlin</category>
      <category>android</category>
      <category>beginners</category>
      <category>calculator</category>
    </item>
    <item>
      <title>quita y pone lista</title>
      <dc:creator>Leo</dc:creator>
      <pubDate>Wed, 25 Sep 2024 15:27:46 +0000</pubDate>
      <link>https://dev.to/imnotleo/quita-y-pone-lista-19eo</link>
      <guid>https://dev.to/imnotleo/quita-y-pone-lista-19eo</guid>
      <description>&lt;p&gt;cpp&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;stdlib.h&amp;gt;
#include &amp;lt;iostream&amp;gt;
#include &amp;lt;string.h&amp;gt;

using namespace std;

#define MAX 20
typedef char TipoDato ;

struct Pila{
            int Tope;
                TipoDato Elementos[MAX];

};

typedef struct Pila TipoPila;

void InicializarPila( TipoPila &amp;amp;P){
    P.Tope= -1;
}

bool PilaVacia(TipoPila P){
    if (P.Tope == -1 )
    return true;
    else
    return false;
}

bool PilaLlena( TipoPila P){
    if(P.Tope == MAX-1)
    return true;
    else
    return false;
}

void PonerPila(TipoPila &amp;amp;P, TipoDato Dato){
    if ( PilaLlena( P ) == true){
        cout &amp;lt;&amp;lt; "la pila esta llena! Overflow";
        system("pause");
    }
    else{
        P.Tope = P.Tope + 1;
        P.Elementos [P.Tope] = Dato;
    }
}

TipoDato QuitarPila(TipoPila &amp;amp;P){
    TipoDato Dato;
    if(PilaVacia ( P ) == true){
        cout &amp;lt;&amp;lt; "la pila esta Vacia! Underflow";
        system("pause");
    }
    else{
        Dato = P.Elementos[ P.Tope ];
        P.Tope = P.Tope - 1;
    }
    return Dato;
}

void CadenaInversa(){

    //Declarar variable del tipo Pila
    TipoPila X;
    char Frase[20];

    //Inicializar el tope 
    InicializarPila( X );

    //Solicitar al usuario el ingreso de una cadena
    cout&amp;lt;&amp;lt; "Escribe una frase: ";
    cin &amp;gt;&amp;gt; Frase;

    //Introducir contenido de cadena o frase dentro de la Pila
    for(int i=0; i&amp;lt;= strlen(Frase)-1; i++)
    PonerPila(X, Frase[i]);

    //Vaciar el contenido de la Pila
    while (PilaVacia ( X )!=true){
        cout&amp;lt;&amp;lt; QuitarPila(X);
}


}

int main (){
    CadenaInversa();
return 0;
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>recursiones e iteraciones</title>
      <dc:creator>Leo</dc:creator>
      <pubDate>Tue, 24 Sep 2024 16:06:56 +0000</pubDate>
      <link>https://dev.to/imnotleo/pila-pone-y-quita-estructura-4chm</link>
      <guid>https://dev.to/imnotleo/pila-pone-y-quita-estructura-4chm</guid>
      <description>&lt;p&gt;cpp&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;stdlib.h&amp;gt;
#include &amp;lt;iostream&amp;gt;
#include &amp;lt;string.h&amp;gt;

using namespace std;

int FactorialRec( int N ) { return N == 0 ? 1 : FactorialRec( N-1 ) * N; }

int FactorialIte( int N )
{
  int fact = 1;

  while ( N &amp;gt; 0 ){

    fact *= N;
    N--;
  }

  return fact;
}

int FibonacciRec( int N ) { return N==0 || N==1 ? N : FibonacciRec( N - 1 ) + FibonacciRec( N - 2 ); }

int FibonacciIte( int N )
{
    if ( ( N == 0) || ( N == 1) ) return N; 

    int fibo, a = 0, b = 1, i = 2;

    while ( i &amp;lt;= N ) {
        fibo = b + a;
        a = b;
        b = fibo;
        i++;
    }

    return fibo;
}

void HanoiRec( int N, char Orig, char Dest, char Aux )         
{
    if ( N == 1 ) cout &amp;lt;&amp;lt; "Mover un disco de " &amp;lt;&amp;lt; Orig &amp;lt;&amp;lt; " a "&amp;lt;&amp;lt; Dest&amp;lt;&amp;lt; endl;

    Hanoi( N - 1, Orig, Aux, Dest);
    cout &amp;lt;&amp;lt; "Mover un disco de " &amp;lt;&amp;lt; Orig &amp;lt;&amp;lt; " a "&amp;lt;&amp;lt; Dest&amp;lt;&amp;lt; endl;
    Hanoi( N - 1, Aux, Dest, Orig);
}

void HanoiIte( int N, char Orig, char Dest, char Aux ){


}

int EuclidesRec( int M, int N ){ return N == 0 ? M : EuclidesRec( N, M % N); }

int EuclidesIte( int M, int N ){

    while ( N != 0 ){

        int x = N;
        N = M % N;
        M = x;
    }

    return M;
}

void Ackermann( int M, int N ){

    if ( M == 0 ){ return N + 1;}

    else {

        if ( N == 0 ) return Ackermann( M - 1, 1 );
        return Ackermann( M - 1, Ackermann( M, N - 1));
    }
}

void MenuPrincipal()
{
  int Opc, Num;
  char Frase[ 20 ];
  char Orig, Dest, Aux;
  int N, M;

  do {
       system("cls");
       cout &amp;lt;&amp;lt; "Ejemplos utilizando algoritmos Recursivos" &amp;lt;&amp;lt; endl;
       cout &amp;lt;&amp;lt; "1. Factorial Recursivo." &amp;lt;&amp;lt; endl;
       cout &amp;lt;&amp;lt; "2. Factorial Iterativo." &amp;lt;&amp;lt; endl;
       cout &amp;lt;&amp;lt; "3. Fibonacci Recursivo." &amp;lt;&amp;lt; endl;
       cout &amp;lt;&amp;lt; "4. Fibonacci Iterativo." &amp;lt;&amp;lt; endl;
       cout &amp;lt;&amp;lt; "5. Euclides Recursivo." &amp;lt;&amp;lt; endl;
       cout &amp;lt;&amp;lt; "6. Euclides Iterativo." &amp;lt;&amp;lt; endl;
       cout &amp;lt;&amp;lt; "7. Invierte Cadena." &amp;lt;&amp;lt; endl;
       cout &amp;lt;&amp;lt; "8. Palindromo." &amp;lt;&amp;lt; endl;
       cout &amp;lt;&amp;lt; "9. Ackermann." &amp;lt;&amp;lt; endl;
       cout &amp;lt;&amp;lt; "10. Torres de Hanoi Recursivo." &amp;lt;&amp;lt; endl;
       cout &amp;lt;&amp;lt; "11. Torres de Hanoi Iterativo." &amp;lt;&amp;lt; endl;
       cout &amp;lt;&amp;lt; "0. Salir." &amp;lt;&amp;lt; endl;

       cout &amp;lt;&amp;lt; "Opcion: "; cin &amp;gt;&amp;gt; Opc;

       switch (Opc) {
         case 1: // Numero factorial
                 system("cls");
                 cout &amp;lt;&amp;lt; "Dame un numero: ";
                 cin &amp;gt;&amp;gt; Num;
                 cout &amp;lt;&amp;lt; "El factorial de " &amp;lt;&amp;lt; Num &amp;lt;&amp;lt; " es = " &amp;lt;&amp;lt; FactorialRec(Num) &amp;lt;&amp;lt; endl;
                 system("Pause");  
                 break;

        case 2: // Serie fibonacci
                 system("cls");
                 cout &amp;lt;&amp;lt; "Dame un numero: ";
                 cin &amp;gt;&amp;gt; Num;
                 cout &amp;lt;&amp;lt; "La serie Fibonacci de " &amp;lt;&amp;lt; Num &amp;lt;&amp;lt; " es = " &amp;lt;&amp;lt; FibonacciRec(Num) &amp;lt;&amp;lt; endl;
                 system("Pause");  
                 break;

        case 3: // Algoritmo de Euclides o MCD

        case 4: // Invierte Cadena
                system("cls");
                cout &amp;lt;&amp;lt; "Escriba una frase: ";
                cin &amp;gt;&amp;gt; Frase;
                //cout &amp;lt;&amp;lt; Invierte( Frase, 0, strlen( Frase )-1 );
                system("PAUSE");
                break;

        case 5: // Palindromo


        case 6: // Algoritmo de Ackermann

        case 7: // Torres de Hanoi
                Orig= 'A';
                Aux= 'B';
                Dest= 'C';

                cout &amp;lt;&amp;lt; "Numero de discos: ";
                cin &amp;gt;&amp;gt; N;

                cout &amp;lt;&amp;lt; "\n Los movimientos a realizar son: \n";
                Hanoi( N, Orig, Dest, Aux);         
                system("Pause");
                break; 
       };            

  } while (Opc!=0);
}

int main (){

  MenuPrincipal(); 
  getchar();

  return 0;
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>otro algoritmos</title>
      <dc:creator>Leo</dc:creator>
      <pubDate>Sat, 18 May 2024 02:13:49 +0000</pubDate>
      <link>https://dev.to/imnotleo/otro-algoritmos-lmc</link>
      <guid>https://dev.to/imnotleo/otro-algoritmos-lmc</guid>
      <description>&lt;p&gt;main&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;iostream&amp;gt;
#include "order.hpp"

int main() {

  srand(time(NULL));
  int n;
  char c;
  cin &amp;gt;&amp;gt; n &amp;gt;&amp;gt; c;

    if (c == 'h' || c == 'H') {

        int *a = new int [n];

      for (int i = 0; i &amp;lt; n; i++){
        int x = rand() % (10*n) + 1;
        a[i] = x;
      }

      cout &amp;lt;&amp;lt; "Array: \n";
        cout &amp;lt;&amp;lt; "[ ";
      for (int i = 0; i &amp;lt; n; i++) cout &amp;lt;&amp;lt; a[i] &amp;lt;&amp;lt;" ";
      cout &amp;lt;&amp;lt; "]\n";

      order m(n);

      for (int i = 0; i &amp;lt; n; i++){
        m.hins(a[i]);
      }

        cout &amp;lt;&amp;lt; "Heapsorted array: \n";
        m.hSort();
        m.print();

    } else if (c == 'q' || c == 'Q') {

        cout &amp;lt;&amp;lt; "Prueba de Q";
        int *a = new int [n];

      for (int i = 0; i &amp;lt; n; i++){
        int x = rand() % (10*n) + 1;
        a[i] = x;
      }

      cout &amp;lt;&amp;lt; "Array: \n";
        cout &amp;lt;&amp;lt; "[ ";
      for (int i = 0; i &amp;lt; n; i++) cout &amp;lt;&amp;lt; a[i] &amp;lt;&amp;lt;" ";
      cout &amp;lt;&amp;lt; "]\n";

        cout &amp;lt;&amp;lt; "Qsorted array: \n";

        //m.mSort();
        m.print();


    } else if (c == 'm' || c == 'M') {

    int *a = new int [n];

      for (int i = 0; i &amp;lt; n; i++){
        int x = rand() % (10*n) + 1;
        a[i] = x;
      }

      cout &amp;lt;&amp;lt; "Array: \n";
        cout &amp;lt;&amp;lt; "[ ";
      for (int i = 0; i &amp;lt; n; i++) cout &amp;lt;&amp;lt; a[i] &amp;lt;&amp;lt;" ";
      cout &amp;lt;&amp;lt; "]\n";



        cout &amp;lt;&amp;lt; "Mergesorted array: \n";

        //m.mSort();
        m.print();

    }

    return 0;

}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;order.cpp&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include "order.hpp"

  order::order(int c){
    n = c;
    s = 0;
    a = new int[n];
  }

  order::~order(){

    delete[] a;
  }

 void order::hins(int x){

   assert(!full());

  a[s] = x;
  int i = s++;
   while (i &amp;gt; 0 &amp;amp;&amp;amp; a[i] &amp;gt; a[parent(i)]) {
     int c = a[i];
     a[i] = a[parent(i)];
     a[parent(i)] = c;

     i = parent(i);
   }

 }

int order::maxChild(int i) {

  assert(i &amp;lt; parent(s));

  if (right(i) &amp;gt; s) return left(i);
  if (a[left(i)] &amp;gt; a[right(i)]) { return left(i); }
  else return right(i);

}

void order::print(){

  cout &amp;lt;&amp;lt; "[ ";
  for (int i = 0; i &amp;lt; s; i++) cout &amp;lt;&amp;lt; a[i] &amp;lt;&amp;lt;" ";
  cout &amp;lt;&amp;lt; "]\n";
}

void order::hSort() {

    int k = s;
    while (k &amp;gt; 0) {
        swap(a[0], a[--k]);
        int i = 0;
        while ( i &amp;lt; parent(k) and a[i] &amp;lt; a[maxChild(i)] ) {
            int m = maxChild(i);
            swap(a[i], a[m]);
            i = m;
        }

    }
    if (a[0] &amp;gt; a[1]) swap(a[0], a[1]);

}
/*
void order::merge() {

  int *c = new int[n+m];
  int i = 0, j = 0, k = 0;
  while (i &amp;lt; n &amp;amp;&amp;amp; j &amp;lt; m) c[k++] = a[i] &amp;lt; b[j] ? a[i++] : b[j++];

    while (i &amp;lt; n) c[k++] = a[i++];
    while (j &amp;lt; m) c[k++] = b[j++];


}

void order::mSort() {

    if (s &amp;gt; 0) {

        int k = s/2;
        int *a = new int [k];
        int *b = new int [k];
        mSort(a);
        mSort(b);
        int *c = merge(a,b);

    }
}

*/




















&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;order.hpp&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#ifndef order_hpp
#define order_hpp

#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;iostream&amp;gt;
#include &amp;lt;cassert&amp;gt;
using namespace std;

class order {

  int parent(int i) { return (i - 1) / 2; }
  int left(int i) { return 2 * i + 1; }
  int right(int i) { return 2 * i + 2; }

  int n; // capacidad
  int s; // tamaño

  int *a; // arreglo

public:

  order(int);
  ~order();

void hins(int);
int maxChild(int);
void hSort();

void mSort();
void merge();

void qSort();

int capacity() const { return n; }
int size() const { return s; }

bool empty() const { return s == 0; }
bool full() const { return s == n; }

void print();
};

#endif /* order_hpp */
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>algoritmo</title>
      <dc:creator>Leo</dc:creator>
      <pubDate>Fri, 17 May 2024 02:16:33 +0000</pubDate>
      <link>https://dev.to/imnotleo/algoritmo-52m7</link>
      <guid>https://dev.to/imnotleo/algoritmo-52m7</guid>
      <description>&lt;p&gt;main.cpp&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;iostream&amp;gt;
#include "heap.hpp"

int main() {

  srand(time(NULL));
  int n;
  char c;
  cin &amp;gt;&amp;gt; n &amp;gt;&amp;gt; c;

    if (c == 'h' || c == 'H') {

        int *a = new int [n];

      for (int i = 0; i &amp;lt; n; i++){
        int x = rand() % (10*n) + 1;
        a[i] = x;
      }

      cout &amp;lt;&amp;lt; "Array: \n";
        cout &amp;lt;&amp;lt; "[ ";
      for (int i = 0; i &amp;lt; n; i++) cout &amp;lt;&amp;lt; a[i] &amp;lt;&amp;lt;" ";
      cout &amp;lt;&amp;lt; "]\n";

      order m(n);

      for (int i = 0; i &amp;lt; n; i++){
        m.ins(a[i]);
      }

        cout &amp;lt;&amp;lt; "Heapsorted array: \n";
        m.hSort();
        m.print();

    } else if (c == 'q' || c == 'Q') {

        cout &amp;lt;&amp;lt; "Prueba de Q";



    } else if (c == 'm' || c == 'M') {

    int *a = new int [n];

      for (int i = 0; i &amp;lt; n; i++){
        int x = rand() % (10*n) + 1;
        a[i] = x;
      }

      cout &amp;lt;&amp;lt; "Array: \n";
        cout &amp;lt;&amp;lt; "[ ";
      for (int i = 0; i &amp;lt; n; i++) cout &amp;lt;&amp;lt; a[i] &amp;lt;&amp;lt;" ";
      cout &amp;lt;&amp;lt; "]\n";

      order m(n);

      for (int i = 0; i &amp;lt; n; i++){
        m.ins(a[i]);
      }

        cout &amp;lt;&amp;lt; "Heapsorted array: \n";

        m.mSort();
        m.print();

    } 

    return 0;

}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;order.cpp&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include "order.hpp"

  order::order(int c){
    n = c;
    s = 0;
    a = new int[n];
  }

  order::~order(){

    delete[] a;
  }

 void order::ins(int x){

   assert(!full());

  a[s] = x;
  int i = s++;
   while (i &amp;gt; 0 &amp;amp;&amp;amp; a[i] &amp;gt; a[parent(i)]) {
     int c = a[i];
     a[i] = a[parent(i)];
     a[parent(i)] = c;

     i = parent(i);
   }

 }

int order::maxChild(int i) {

  assert(i &amp;lt; parent(s));

  if (right(i) &amp;gt; s) return left(i);
  if (a[left(i)] &amp;gt; a[right(i)]) { return left(i); }
  else return right(i);

}

void order::print(){

  cout &amp;lt;&amp;lt; "[ ";
  for (int i = 0; i &amp;lt; s; i++) cout &amp;lt;&amp;lt; a[i] &amp;lt;&amp;lt;" ";
  cout &amp;lt;&amp;lt; "]\n";
}

void order::hSort() {

    int k = s;
    while (k &amp;gt; 0) {
        swap(a[0], a[--k]);
        int i = 0;
        while ( i &amp;lt; parent(k) and a[i] &amp;lt; a[maxChild(i)] ) {
            int m = maxChild(i);
            swap(a[i], a[m]);
            i = m;
        }

    }
    if (a[0] &amp;gt; a[1]) swap(a[0], a[1]);

}

void order::merge() {

  int *c = new int[n+m];
  int i = 0, j = 0, k = 0;
  while (i &amp;lt; n &amp;amp;&amp;amp; j &amp;lt; m) c[k++] = a[i] &amp;lt; b[j] ? a[i++] : b[j++];

    while (i &amp;lt; n) c[k++] = a[i++];
    while (j &amp;lt; m) c[k++] = b[j++];


}

void order::mSort() {

    if (s &amp;gt; 0) {

        int k = s/2;
        int *a = new int [k];
        int *b = new int [k];
        mSort(a);
        mSort(b);
        int *c = merge(a,b);

    }
}











&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;order.hpp&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include "order.hpp"

  order::order(int c){
    n = c;
    s = 0;
    a = new int[n];
  }

  order::~order(){

    delete[] a;
  }

 void order::ins(int x){

   assert(!full());

  a[s] = x;
  int i = s++;
   while (i &amp;gt; 0 &amp;amp;&amp;amp; a[i] &amp;gt; a[parent(i)]) {
     int c = a[i];
     a[i] = a[parent(i)];
     a[parent(i)] = c;

     i = parent(i);
   }

 }

int order::maxChild(int i) {

  assert(i &amp;lt; parent(s));

  if (right(i) &amp;gt; s) return left(i);
  if (a[left(i)] &amp;gt; a[right(i)]) { return left(i); }
  else return right(i);

}

void order::print(){

  cout &amp;lt;&amp;lt; "[ ";
  for (int i = 0; i &amp;lt; s; i++) cout &amp;lt;&amp;lt; a[i] &amp;lt;&amp;lt;" ";
  cout &amp;lt;&amp;lt; "]\n";
}

void order::hSort() {

    int k = s;
    while (k &amp;gt; 0) {
        swap(a[0], a[--k]);
        int i = 0;
        while ( i &amp;lt; parent(k) and a[i] &amp;lt; a[maxChild(i)] ) {
            int m = maxChild(i);
            swap(a[i], a[m]);
            i = m;
        }

    }
    if (a[0] &amp;gt; a[1]) swap(a[0], a[1]);

}

void order::merge() {

  int *c = new int[n+m];
  int i = 0, j = 0, k = 0;
  while (i &amp;lt; n &amp;amp;&amp;amp; j &amp;lt; m) c[k++] = a[i] &amp;lt; b[j] ? a[i++] : b[j++];

    while (i &amp;lt; n) c[k++] = a[i++];
    while (j &amp;lt; m) c[k++] = b[j++];


}

void order::mSort() {

    if (s &amp;gt; 0) {

        int k = s/2;
        int *a = new int [k];
        int *b = new int [k];
        mSort(a);
        mSort(b);
        int *c = merge(a,b);

    }
}











&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>prueba de algoritmos</title>
      <dc:creator>Leo</dc:creator>
      <pubDate>Tue, 14 May 2024 02:25:40 +0000</pubDate>
      <link>https://dev.to/imnotleo/prueba-de-algoritmos-2gn5</link>
      <guid>https://dev.to/imnotleo/prueba-de-algoritmos-2gn5</guid>
      <description>&lt;p&gt;main.cpp&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;iostream&amp;gt;
#include "heap.hpp"

int main() {

  srand(time(NULL));
  int n;
  char c;
  cin &amp;gt;&amp;gt; n &amp;gt;&amp;gt; c;

    if (c == 'h' || c == 'H') {

        int *a = new int [n];

      for (int i = 0; i &amp;lt; n; i++){
        int x = rand() % (10*n) + 1;
        a[i] = x;
      }

      cout &amp;lt;&amp;lt; "Array: \n";
        cout &amp;lt;&amp;lt; "[ ";
      for (int i = 0; i &amp;lt; n; i++) cout &amp;lt;&amp;lt; a[i] &amp;lt;&amp;lt;" ";
      cout &amp;lt;&amp;lt; "]\n";

      heap m(n);

      for (int i = 0; i &amp;lt; n; i++){
        m.ins(a[i]);
      }

        cout &amp;lt;&amp;lt; "Heapsorted array: \n";
        m.hSort();
        m.print();

    } else if (c == 'q' || c == 'Q') {

        cout &amp;lt;&amp;lt; "Prueba de Q";



    } else if (c == 'm' || c == 'M') {

        cout &amp;lt;&amp;lt; "Prueba de M";


    } 

    return 0;

}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;heap.cpp&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

#include "heap.hpp"

  heap::heap(int c){
    n = c;
    s = 0;
    a = new int[n];
  }

  heap::~heap(){

    delete[] a;
  }

 void heap::ins(int x){

   assert(!full());

  a[s] = x;
  int i = s++;
   while (i &amp;gt; 0 &amp;amp;&amp;amp; a[i] &amp;gt; a[parent(i)]) {
     int c = a[i];
     a[i] = a[parent(i)];
     a[parent(i)] = c;

     i = parent(i);
   }

 }

int heap::tout(){
  assert(!empty());

  int x = a[0];
  int i = 0;
  a[0] = a[--s];
  while (i &amp;lt;= parent(s-1) &amp;amp;&amp;amp; a[i] &amp;lt; a[maxChild(i)]){

    int m = maxChild(i);
    int c = a[i];
    a[i] = a[m];
    a[m] = c;
    i = m;
  }

    return x;
}

int heap::maxChild(int i) {

  assert(i &amp;lt; parent(s));

  if (right(i) &amp;gt; s) return left(i);
  if (a[left(i)] &amp;gt; a[right(i)]) { return left(i); }
  else return right(i);

}

void heap::print(){

  cout &amp;lt;&amp;lt; "[ ";
  for (int i = 0; i &amp;lt; s; i++) cout &amp;lt;&amp;lt; a[i] &amp;lt;&amp;lt;" ";
  cout &amp;lt;&amp;lt; "]\n";
}

void heap::hSort() {

    int k = s;
    while (k &amp;gt; 0) {
        swap(a[0], a[--k]);
        int i = 0;
        while ( i &amp;lt; parent(k) and a[i] &amp;lt; a[maxChild(i)] ) {
            int m = maxChild(i);
            swap(a[i], a[m]);
            i = m;
        }

    }

}




&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;heap.hpp&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#ifndef heap_hpp
#define heap_hpp

#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;iostream&amp;gt;
#include &amp;lt;cassert&amp;gt;
using namespace std;

class heap {

  int parent(int i) { return (i - 1) / 2; }
  int left(int i) { return 2 * i + 1; }
  int right(int i) { return 2 * i + 2; }

  int n; // capacidad
  int s; // tamaño

  int *a; // arreglo

public:

  heap(int);
  ~heap();

void ins(int);
int tout();
int maxChild(int);
void hSort();

int capacity() const { return n; }
int size() const { return s; }

bool empty() const { return s == 0; }
bool full() const { return s == n; }

void print();
};

#endif /* stack_hpp */

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>chat</title>
      <dc:creator>Leo</dc:creator>
      <pubDate>Tue, 07 May 2024 15:12:25 +0000</pubDate>
      <link>https://dev.to/imnotleo/chat-5464</link>
      <guid>https://dev.to/imnotleo/chat-5464</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn29smv6skfftrj5ph97u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn29smv6skfftrj5ph97u.png" alt="Image description" width="800" height="470"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5acapsipt1h4aludlpxm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5acapsipt1h4aludlpxm.png" alt="Image description" width="800" height="577"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwj2dnfgwaafz8h9zwo2e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwj2dnfgwaafz8h9zwo2e.png" alt="Image description" width="800" height="555"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>heap minchild</title>
      <dc:creator>Leo</dc:creator>
      <pubDate>Tue, 07 May 2024 15:11:02 +0000</pubDate>
      <link>https://dev.to/imnotleo/heap-minchild-p3c</link>
      <guid>https://dev.to/imnotleo/heap-minchild-p3c</guid>
      <description>&lt;p&gt;hpp&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#ifndef heap_hpp
#define heap_hpp

#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;iostream&amp;gt;
#include &amp;lt;cassert&amp;gt;
using namespace std;

class heap {

  int parent(int i) { return (i - 1) / 2; }
  int left(int i) { return 2 * i + 1; }
  int right(int i) { return 2 * i + 2; }

  int n; // capacidad
  int s; // tamaño

  int *a; // arreglo

public:

  heap(int);
  ~heap();

void ins(int);
int tout();
int minChild(int);

int capacity() const { return n; }
int size() const { return s; }

bool empty() const { return s == 0; }
bool full() const { return s == n; }

void print();
};

#endif /* stack_hpp */
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>heap minchild</title>
      <dc:creator>Leo</dc:creator>
      <pubDate>Thu, 02 May 2024 21:40:09 +0000</pubDate>
      <link>https://dev.to/imnotleo/heap-minchild-5h9o</link>
      <guid>https://dev.to/imnotleo/heap-minchild-5h9o</guid>
      <description>&lt;p&gt;hpp&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#ifndef heap_hpp
#define heap_hpp

#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;iostream&amp;gt;
#include &amp;lt;cassert&amp;gt;
using namespace std;

class heap {

  int parent(int i) { return (i - 1) / 2; }
  int left(int i) { return 2 * i + 1; }
  int right(int i) { return 2 * i + 2; }

  int n; // capacidad
  int s; // tamaño

  int *a; // arreglo

public:

  heap(int);
  ~heap();

void ins(int);
int tout();
int minChild(int);

int capacity() const { return n; }
int size() const { return s; }

bool empty() const { return s == 0; }
bool full() const { return s == n; }

void print();
};

#endif /* stack_hpp */
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;cpp&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include "heap.hpp"

  heap::heap(int c){

    n = c;
    s = 0;

    a = new int[n];
  }

  heap::~heap(){

    delete[] a;
  }

 void heap::ins(int x){

   assert(!full());

  a[s] = x;
  int i = s++;
   while (i &amp;gt; 0 &amp;amp;&amp;amp; a[i] &amp;gt; a[parent(i)]) {
     int c = a[i];
     a[i] = a[parent(i)];
     a[parent(i)] = c;

     i = parent(i);
   }

 }

int heap::tout(){
  assert(!empty());

  int x = a[0];
  int i = 0;
  a[0] = a[--s];
  while (i &amp;lt;= parent(s-1) &amp;amp;&amp;amp; a[i] &amp;gt; a[minChild(i)]){

    int m = minChild(i);
    int c = a[i];
    a[i] = a[m];
    a[m] = c;
    i = m;
  }

    return x;
}

int heap::minChild(int i) {

  assert(i &amp;lt;= parent(s-1));

  if (right(i) &amp;gt; s-1) return left(i);
  if (a[left(i)] &amp;gt; a[right(i)]) { return left(i); }
  else return right(i);

}

void heap::print(){

  cout &amp;lt;&amp;lt; "[ ";
  for (int i = 0; i &amp;lt; s; i++) cout &amp;lt;&amp;lt; a[i] &amp;lt;&amp;lt;" ";
  cout &amp;lt;&amp;lt; "]\n";
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;main&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;iostream&amp;gt;
#include "heap.hpp"

int main() {

  srand((unsigned) time(nullptr));

  int n = 100;

  heap m(n);

  for (int i = 0; i &amp;lt; 10; i++){

    int x = rand() % n + 1;

    cout &amp;lt;&amp;lt; "Agregar " &amp;lt;&amp;lt; x &amp;lt;&amp;lt; ": ";

    m.ins(x);
    m.print();
  }

  cout &amp;lt;&amp;lt; "\n\n";
  m.print();
  cout &amp;lt;&amp;lt; "\n\n";
  for (int i = 0; i &amp;lt; 10; i++){

    cout &amp;lt;&amp;lt; "Extraer " &amp;lt;&amp;lt; m.tout() &amp;lt;&amp;lt; ": ";

    m.print();
  }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>chat heap minchild</title>
      <dc:creator>Leo</dc:creator>
      <pubDate>Thu, 02 May 2024 18:17:46 +0000</pubDate>
      <link>https://dev.to/imnotleo/chat-heap-minchild-5934</link>
      <guid>https://dev.to/imnotleo/chat-heap-minchild-5934</guid>
      <description>&lt;p&gt;Para modificar la implementación para que tout() extraiga el elemento más pequeño en lugar del más grande, necesitas ajustar la lógica en la función maxChild() y en el bucle while dentro de tout().&lt;/p&gt;

&lt;p&gt;Aquí hay una forma de hacerlo:&lt;/p&gt;

&lt;p&gt;En la función maxChild(), en lugar de buscar el hijo con el mayor valor, debes buscar el hijo con el menor valor.&lt;br&gt;
En el bucle while dentro de tout(), en lugar de comparar a[i] con a[maxChild(i)], debes comparar a[i] con el hijo más pequeño.&lt;br&gt;
Aquí tienes los cambios necesarios en tu código:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int heap::maxChild(int i) {
    assert(i &amp;lt;= parent(s-1));

    if (right(i) &amp;gt;= s) return left(i);
    if (a[left(i)] &amp;lt; a[right(i)]) { // Cambiado de '&amp;gt;' a '&amp;lt;' para buscar el hijo más pequeño
        return left(i);
    } else {
        return right(i);
    }
}

int heap::tout() {
    assert(!empty());

    int x = a[0];
    int i = 0;
    a[0] = a[--s]; // Decremento de s después de asignar el último elemento al principio
    while (i &amp;lt;= parent(s) &amp;amp;&amp;amp; a[i] &amp;gt; a[minChild(i)]) { // Cambiado de '&amp;lt;' a '&amp;gt;' para buscar el hijo más pequeño
        int m = minChild(i); // Cambiado a minChild
        int c = a[i];
        a[i] = a[m];
        a[m] = c;
        i = m;
    }

    return x;
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
  </channel>
</rss>
