Hola a todos.
Mi nombre es Rosely.
En esta ocasión vengo a pedirles su ayuda.
La maestra nos pidió un los programas de métodos de ordenación y búsqueda en la materia de estructuras de datos.
No se programar mucho en c o c++, y se me dificulta pasarlo a visual basic.
Este es el código en c:
#include <stdio.h>
#include<conio.h>
#define MAX 5
#define SHOWPASS
void print(int *a,int n)
{
int i;
for(i=0;i<n;i++)
printf("%dt",a);
}
void radixsort(int *a,int n)
{
int i,b[MAX],m=0,exp=1;
for(i=0;i<n;i++)
{
if(a>m)
m=a;
}
while(m/exp>0)
{
int bucket[10]={0};
for(i=0;i<n;i++)
bucket[a/exp%10]++;
for(i=1;i<10;i++)
bucket+=bucket[i-1];
for(i=n-1;i>=0;i--)
b[--bucket[a/exp%10]]=a;
for(i=0;i<n;i++)
a=b;
exp*=10;
#ifdef SHOWPASS
printf("nPASS : ";
print(a,n);
#endif
}
}
int main()
{
int arr[MAX];
int i,n;
printf("Enter total elements (n < %d) : ",MAX);
scanf("%d",&n);
printf("Enter %d Elements : ",n);
for(i=0;i<n;i++)
scanf("%d",&arr);
printf("nARRAY : ";
print(&arr[0],n);
radixsort(&arr[0],n);
printf("nSORTED : ";
print(&arr[0],n);
printf("n";
return 0;
}
y hasta ahora este es el codigo que tengo en visual basic.
Const MAX As Integer = 5
Dim d As Integer
Private Sub Form_Load()
Dim arr(MAX) As Integer
Dim i, n As Integer
n = 4
For i = 1 To n
arr(i) = InputBox("Ingrese un valor"
List1.AddItem arr(i)
Next
Call radixsort(arr, n)
Call printx(arr, n)
End Sub
Sub radixsort(a() As Integer, n As Integer)
Dim i, b(MAX), m, exp As Integer
m = 0
exp = 1
For i = 1 To n
If (a(i) > m) Then
m = a(i)
End If
Next
While (m / exp > 0)
Dim bucket(10) As Integer
bucket(10) = 0
For i = 0 To n
bucket(i) = a(i) / exp Mod 10
'b(a(i) / exp Mod 10) = (a(i) / exp Mod 10) + 1
'bucket(a(i) / exp Mod 10) = bucket(a(i) / exp Mod 10) + 1
Next
For i = 1 To 9
bucket(i) = bucket(i) + bucket(i - 1)
Next
For i = n - 1 To 0
bucket(-1) = a(i)
' b(bucket(a(i) / exp Mod 10)) = a(i)
Next
For i = 0 To n
a(i) = b(i)
Next
exp = 10
Wend
Call printx(a, n)
End Sub
Sub printx(a() As Integer, n As Integer)
Dim i As Integer
For i = 0 To n
List2.AddItem a(i)
Next
End Sub
Mi problema esta en el while y los no se como interpretarlos, se que son incrementos pero no se como traducirlos en visual basic, por favor ayudenme, estoy bloqueda.
De antemano les agradezco su ayuda.
Mi nombre es Rosely.
En esta ocasión vengo a pedirles su ayuda.
La maestra nos pidió un los programas de métodos de ordenación y búsqueda en la materia de estructuras de datos.
No se programar mucho en c o c++, y se me dificulta pasarlo a visual basic.
Este es el código en c:
#include <stdio.h>
#include<conio.h>
#define MAX 5
#define SHOWPASS
void print(int *a,int n)
{
int i;
for(i=0;i<n;i++)
printf("%dt",a);
}
void radixsort(int *a,int n)
{
int i,b[MAX],m=0,exp=1;
for(i=0;i<n;i++)
{
if(a>m)
m=a;
}
while(m/exp>0)
{
int bucket[10]={0};
for(i=0;i<n;i++)
bucket[a/exp%10]++;
for(i=1;i<10;i++)
bucket+=bucket[i-1];
for(i=n-1;i>=0;i--)
b[--bucket[a/exp%10]]=a;
for(i=0;i<n;i++)
a=b;
exp*=10;
#ifdef SHOWPASS
printf("nPASS : ";
print(a,n);
#endif
}
}
int main()
{
int arr[MAX];
int i,n;
printf("Enter total elements (n < %d) : ",MAX);
scanf("%d",&n);
printf("Enter %d Elements : ",n);
for(i=0;i<n;i++)
scanf("%d",&arr);
printf("nARRAY : ";
print(&arr[0],n);
radixsort(&arr[0],n);
printf("nSORTED : ";
print(&arr[0],n);
printf("n";
return 0;
}
y hasta ahora este es el codigo que tengo en visual basic.
Const MAX As Integer = 5
Dim d As Integer
Private Sub Form_Load()
Dim arr(MAX) As Integer
Dim i, n As Integer
n = 4
For i = 1 To n
arr(i) = InputBox("Ingrese un valor"
List1.AddItem arr(i)
Next
Call radixsort(arr, n)
Call printx(arr, n)
End Sub
Sub radixsort(a() As Integer, n As Integer)
Dim i, b(MAX), m, exp As Integer
m = 0
exp = 1
For i = 1 To n
If (a(i) > m) Then
m = a(i)
End If
Next
While (m / exp > 0)
Dim bucket(10) As Integer
bucket(10) = 0
For i = 0 To n
bucket(i) = a(i) / exp Mod 10
'b(a(i) / exp Mod 10) = (a(i) / exp Mod 10) + 1
'bucket(a(i) / exp Mod 10) = bucket(a(i) / exp Mod 10) + 1
Next
For i = 1 To 9
bucket(i) = bucket(i) + bucket(i - 1)
Next
For i = n - 1 To 0
bucket(-1) = a(i)
' b(bucket(a(i) / exp Mod 10)) = a(i)
Next
For i = 0 To n
a(i) = b(i)
Next
exp = 10
Wend
Call printx(a, n)
End Sub
Sub printx(a() As Integer, n As Integer)
Dim i As Integer
For i = 0 To n
List2.AddItem a(i)
Next
End Sub
Mi problema esta en el while y los no se como interpretarlos, se que son incrementos pero no se como traducirlos en visual basic, por favor ayudenme, estoy bloqueda.
De antemano les agradezco su ayuda.

