Skip to content

Instantly share code, notes, and snippets.

@alrami26
Created August 27, 2012 04:20
Show Gist options
  • Save alrami26/3485507 to your computer and use it in GitHub Desktop.
Save alrami26/3485507 to your computer and use it in GitHub Desktop.
Tarea Ordenamiento de matrices Albin Ramirez
//Albin Ramirez Tarea Estructuras
#include "stdafx.h"
#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include <string.h>
#include <sstream>
#include <assert.h>
#include <string.h>
#include <iostream>
#include <cstdlib>
using namespace System;
using namespace std;
void swap(int arreglo[], int i, int j)
{
int temp=arreglo[i];
arreglo[i]=arreglo[j];
arreglo[j]=temp;
}
/*void insertionSort(int *arreglo)
{
for (int j=1; j<6;j++)
{
int key=arreglo[j];
int i = j - 1;
while (i >= 0 && arreglo[i]<key)
{
arreglo[i+1] = arreglo[i];
i--;
}
arreglo[i+1]=key;
}
}*/
void SortMatrix(int arreglo[3][6])
{
int jk=10;
for (int i=0; i<3;i++)
{
for (int j=0; j<6;j++)
{
if(((i+j)%2)==0)
{
arreglo[i][j]=(i+j)/2;
}
else
arreglo[i][j]=i+j;
}
}
cout<<"Matriz Inicial:"<<endl;
for (int i=0; i<3;i++)
{
for (int j=0; j<6;j++)
{
cout<<arreglo[i][j];
}
cout<<endl;
}
cout<<endl;
cout<<endl;
for (int h=0; h<3;h++)
{
for (int j=1; j<6;j++)
{
int key=arreglo[h][j];
int i = j - 1;
while (i >= 0 && arreglo[h][i]>key)
{
arreglo[h][i+1] = arreglo[h][i];
i--;
}
arreglo[h][i+1]=key;
}
}
for (int j=1; j<3;j++)
{
int key=arreglo[j][0];
int i = j - 1;
while (i >= 0 && arreglo[i][0]<key)
{
arreglo[i+1][0] = arreglo[i][0];
for (int l=1; l<6;l++)
{
int temp=arreglo[i+1][l];
arreglo[i+1][l] = arreglo[i][l];
arreglo[i][l] = temp;
}
i--;
}
arreglo[i+1][0]=key;
}
cout<<"Matriz Final:"<<endl;
for (int i=0; i<3;i++)
{
for (int j=0; j<6;j++)
{
cout<<arreglo[i][j];
}
cout<<endl;
}
}
int main(array<System::String ^> ^args)
{
int arreglo[3][6];
SortMatrix(arreglo);
getch();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment