Recursividad en c+++builder

Páginas: 13 (3070 palabras) Publicado: 2 de junio de 2011
Programa # 1
///cargar un vector randomicamente///
Ir a Additional->StringGrid y crear uno y poner en name del StringGrid con vec.
void CargarRandom(TStringGrid *v,byte n){
if(n>0){
CargarRandom(v,n-1);
v->Cells[n-1][0]=random(40);
}
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{ byte n;
n=StrToInt(InputBox("Cargar Rand:","N=","4"));
randomize();vec->ColCount=n;
CargarRandom(vec,n);
}
Programa # 2
///cargar un vector manualmente///
Crear un edit y un label. Hacer un click sobre el TstringGrid ir a Object Inspecto->Property->Options->goEditing y cambiar a true.
Y luego hacer un click en Edit1 ir a Object Inspecto->Events->OnExit y doble click y escribir esto :
void __fastcall TForm1::Edit1Exit(TObject *Sender)
{vec->ColCount=StrToInt(Edit1->Text);
}
Programa # 3
/////suma de los elementos del vector///////////////
int SumaEle(TStringGrid *v,byte n){
int sum;
if(n==0){
sum=0;
}else{
sum=SumaEle(v,n-1);
sum=sum+ StrToInt(v->Cells[n-1][0]);
}
return sum;
}
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Label3->Caption="la suma de suselementos del vector es:= " +IntToStr(SumaEle(vec,vec->ColCount));
}
Programa # 3
/////suma de los elementos pares del vector ///////////////
int SumaElePar(TStringGrid *v,int n){
byte sump;
if(n==0){
sump=0;
}else{
sump=SumaElePar(v,n-1);
if(StrToInt(v->Cells[n-1][0])%2==0){
sump=sump+StrToInt(v->Cells[n-1][0]);
}
}
return sump;
}void __fastcall TForm1::Button3Click(TObject *Sender)
{
Label3->Caption="la suma de sus elementos pares es: "+ IntToStr(SumaElePar(vec,vec->ColCount));
}
Programa # 4
/////burbujear ///////////////
Lleva el mayor al final ejemplo:
5-212-231-12 ->5-212-12-231
3-23-12-32-2 ->3-23-12-2-32
void Burbujear(TStringGrid *v,byte n){
byte x;
if(n>1){
Burbujear(v,n-1);if(StrToInt(v->Cells[n-2][0])>StrToInt(v->Cells[n-1][0])){
x=StrToInt(v->Cells[n-1][0]);
v->Cells[n-1][0]=v->Cells[n-2][0];
v->Cells[n-2][0]=x;
}
}
}
void __fastcall TForm1::Button4Click(TObject *Sender)
{
Burbujear(vec,vec->ColCount);
}
Programa # 5
/////// metodo de ordenamiento bubles ////////
Ordena elvector de menor a mayor .
Ejemplo: 4-2-12-0-8->0-2-4-8-12
void Bubles(TStringGrid *v,byte n){
if(n>1){
Burbujear(v,n);
Bubles(v,n-1);
}
}
void __fastcall TForm1::Button5Click(TObject *Sender)
{
Bubles(vec,vec->ColCount);
}
Programa # 6
/////// Invertir un vector ////////
void Invertir(TStringGrid * v,byte a,byte b)
{ byte x;if((b!=a)&&(b>=a)){
Invertir(v,a+1,b-1);
x=StrToInt(v->Cells[a][0]);
v->Cells[a][0]=v->Cells[b][0];
v->Cells[b][0]=x;
}
}
void __fastcall TForm1::Button6Click(TObject *Sender)
{
Invertir(vec,0,vec->ColCount-1);
}
Programa # 7
/////// mostrar la posicion del mayor elemento de un vector ////////
byte PosMayor(TStringGrid *v,byte n){byte p;
if (n==0) {
throw new Exception("Error");
}else{
if (n==1){
p=0;
}else{
p=PosMayor(v,n-1);
if (StrToInt(v->Cells[n-1][0])>StrToInt(v->Cells[p][0])){
p=n-1;
}
}
}
return p;
}
void __fastcall TForm1::Button7Click(TObject *Sender)
{
ShowMessage(PosMayor(vec,vec->ColCount));
}Programa # 8
///// introducir un vector(B) en un vector (A) en una posicion P////////
void Introducir(TStringGrid*v2,TStringGrid*v1,int n,int pon){
if(n>0){
pon=pon-1;
v2->Cells[pon-1][0]=v1->Cells[n-1][0];
Introducir(v2,v1,n-1,pon);
}
}
void ColocarVec(TStringGrid*v,TStringGrid*v1,TStringGrid*v2,int p,int n,int &c){
if((n>0)&&(p>=0)){...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • C++Builder Conexion A Bdd
  • RECURSO DE APELACION DE LA C
  • Lenguaje En C, Recursividad
  • Programación En C
  • Instalación Y Compilación En Netbeans 6.1 Y Borland Builder C/C++
  • Caracterisaticas de c++ builder
  • Programación en c++ builder
  • Programación En Builder C++

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS