Dev - C++ - CONSULTA - Codigo C# - Ordenamiento de ArrayList

 
Vista:
Imágen de perfil de Mariano

CONSULTA - Codigo C# - Ordenamiento de ArrayList

Publicado por Mariano (1 intervención) el 11/04/2018 18:08:05
Que tal gente, estoy comenzando a estudiar programación. Me mandaron un TP en el cual tengo uno de los ejercicios donde me piden ordenar un arraylist con números ingresados por el usuario, es decir los debo mostrar en orden, ya sea de menor a mayor o viceversa. Busque muchos tutoriales pero no logro hacer que mi codigo funcione. Me dan una mano?


Codigo:

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
using System;
using System.Linq;
using System.Collections;
 
 
 
namespace Ejercicio_4
{
	class Program
	{
		public static void Main(string[] args)
		{
 
			ArrayList numeros = new ArrayList();
			string respuesta = "si";
			int num = 0;
			int cantidad = 0;
			int flag = 0;
 
			while(respuesta!="no") // ACA INTENTO CREAR UN BUCLE DONDE PIDA NUMEROS HASTA DECIR NO
			{
				Console.Write("Ingrese numero :");
				num=int.Parse(Console.ReadLine());
				numeros.Add(num);
				Console.Write("Desea seguir agregando numeros?");
				respuesta=Console.ReadLine();
			}
 
			cantidad=numeros.Count;   // ACA DEFINO LA CANTIDAD DE ITERACIONES SEGUN LA CANTIDAD DE ELEMENTOS QUE TENGO EN EL ARRAY
 
			for(int i = 0; i<cantidad;i++) // Y EN ESTE BUSCO QUE EL FOR RECORRA LA LISTA Y TOME DOS POSICIONES Y LAS COMPARE
			{
				for(int j = 0; j<cantidad;j++)
				{
 
					if(numeros[j] > numeros[j+1])
					{
						flag = numeros[j]; // DONDE ACA SE GUARDAN Y DESPUES REEMPLAZO
						numeros[j]=numeros[j+1];
						numeros[j+1]=flag;
 
					}
				}
 
			}
 
			for(int i = 0; i<cantidad; i++)
			{
				Console.WriteLine(numeros[i]);
			}
 
			Console.ReadKey(true);
 
		}
	}
}


ERROR DEL COMPILADOR:

Operator '>' cannot be applied to operands of type 'object' and 'object' (CS0019) - d:\Users\mloprete\Desktop\Facultad\Algoritmos y Programacion\Practicas\1\Practica 1\Ejercicio 4\Program.cs:46,9

Cannot implicitly convert type 'object' to 'int'. An explicit conversion exists (are you missing a cast?) (CS0266) - d:\Users\mloprete\Desktop\Facultad\Algoritmos y Programacion\Practicas\1\Practica 1\Ejercicio 4\Program.cs:48,14

Disculpen si el error es muy obvio, soy novato. Capas también tenga algún problema de logica....
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