DUDA PEQUEÑA SOBRE UN ADGORITMO VECTOR
Publicado por 11 (2 intervenciones) el 28/11/2013 02:08:19
Cargar un vector de n elementos de tipo entero. Ordenar posteriormente el vector.
En el metodo ordenar es mi duda ,en la parte del for interno se lo puede representar asi tambien:
for (int f = 1; f < vec.Length - k; f++)?
el menos 1 que le ponen es por el numero que van a cargar ? es para que no se le sume un ellemento mas ya que el indice de f comienza con 0?
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PruebaVector15
{
class PruebaVector15
{
private int[] vec;
public void Cargar()
{
Console.Write("Cuantos elementos tendrá el vector:");
string linea;
linea = Console.ReadLine();
int cant;
cant=int.Parse(linea);
vec=new int[cant];
for(int f=0;f < vec.Length;f++)
{
Console.Write("Ingrese elemento:");
linea = Console.ReadLine();
vec[f]=int.Parse(linea);
}
}
public void Ordenar()
{
for (int k = 0; k < vec.Length; k++)
{
for (int f = 0; f < vec.Length - 1 - k; f++)
{
if (vec[f] > vec[f + 1])
{
int aux;
aux = vec[f];
vec[f] = vec[f + 1];
vec[f + 1] = aux;
}
}
}
}
public void Imprimir()
{
Console.WriteLine("Vector ordenados de menor a mayor.");
for(int f=0;f < vec.Length;f++)
{
Console.WriteLine(vec[f]);
}
Console.ReadKey();
}
static void Main(string[] args)
{
PruebaVector15 pv = new PruebaVector15();
pv.Cargar();
pv.Ordenar();
pv.Imprimir();
}
}
}
En el metodo ordenar es mi duda ,en la parte del for interno se lo puede representar asi tambien:
for (int f = 1; f < vec.Length - k; f++)?
el menos 1 que le ponen es por el numero que van a cargar ? es para que no se le sume un ellemento mas ya que el indice de f comienza con 0?
Valora esta pregunta


0