Dev - C++ - Ordenar una matriz en forma de culebrita urgentísimo):

 
Vista:
sin imagen de perfil
Val: 2
Ha aumentado su posición en 802 puestos en Dev - C++ (en relación al último mes)
Gráfica de Dev - C++

Ordenar una matriz en forma de culebrita urgentísimo):

Publicado por Jose (1 intervención) el 09/06/2021 04:24:49
Piden hacer un programa en el cual primero se introducen el numero de filas y columnas de la matriz. Después se le introducen valores a esta. (Hasta aquí pude hacer el programa), después la matriz introducida se tiene que ordenar como se muestra en la foto, inicia en el punto azul y terminar en el verde, yo intenté hacer el método de la burbuja con las columnas, pero no obtuve el recorrido que quería... de todas maneras ahí dejo mi codugo, espero me puedan ayudar)):

20210608-213958

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <iostream>
#include <iomanip>
 
int matriz[100];
 
using namespace std;
 
		int main() {
	int m, n;
 
	cout << "DIMENSION DE LA MATRIZ"<<endl<<endl;
	cout << ">> Introduzca el numero de filas: ";
	cin >> m;
	cout << ">> Introduzca el numero de columnas: ";
	cin >> n;
	cout << endl <<"La matriz tendra una dimension de [ " <<m <<" , " <<n <<" ]"<<endl;
	cout << "---------------------------------------------------"<<endl<<endl;
	cout << "LLENADO DE VALORES DE LA MATRIZ"<<endl;
 
		int matriz[m][n];
 
	for (int i= 0; i < m; i++) {
		for (int j= 0; j < n; j++) {
			cout <<endl;
			cout << "Introduzca valores de la posicion [ "<< i+1 << " ; " << j+1<<" ] para la matriz: ";
			cin >> matriz[i][j];
		}
	}
 
	cout << "---------------------------------------------------"<<endl<<endl;
	cout << "2. Matriz sin ordenar"<<endl;
for (int i= 0; i < m; i++) {
	cout << "|"<<setw(4);
		for (int j= 0; j < n; j++) {
			cout << matriz[i][j]<<setw(4);
		}
		cout << "|" <<endl;
	}
	cout << "---------------------------------------------------"<<endl<<endl;
 
	int aux=0;
 
	for (int j= 0; j < n; j++) {
		for (int i= 0; i < m; i++) {
			for (int j1=j ; j1 < n ; j1++) {
 
				int iaux = 0;
				if (j == j1){
					iaux = i+1;
				}
 
				for (int i1=iaux ; i1 < m; i1++) {
					if(matriz[i][j] < matriz[i1][j1]){
						aux = matriz[i][j];
						matriz[i][j] = matriz[i1][j1];
						matriz[i1][j1] = aux;
					}
					}
				}
			}
		}
 
 
 
	cout << "Matriz ordenada"<<endl;
for (int i= 0; i < m; i++) {
	cout << "|"<<setw(4);
		for (int j= 0; j < n; j++) {
			cout << matriz[i][j]<<setw(4);
		}
		cout << "|" <<endl;
	}
	cout << "---------------------------------------------------"<<endl<<endl;
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder