elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Únete al Grupo Steam elhacker.NET


  Mostrar Mensajes
Páginas: 1 ... 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 [58] 59 60 61 62 63 64
571  Programación / Programación C/C++ / Re: Ayuda con recursividad en: 16 Septiembre 2018, 16:35 pm
Que bueno, yo recien acabo de empezar el secundario primer año
572  Programación / Programación C/C++ / Re: invertir un vector en C en: 16 Septiembre 2018, 04:46 am
Ahora que me doy cuenta la mejor forma de invertir un vector sin usar otro auxiliar es hacer un bubblesort que traiga el ultimo elemento a la primera posicion del arreglo y ya  ;-)
573  Programación / Programación C/C++ / Re: RECURSION en su estado mas puro para invertir un vector! en: 16 Septiembre 2018, 04:32 am
Código
  1. #include <iostream>
  2. #include <ctime>
  3.  
  4. using namespace std;
  5.  
  6. const int FILAS=3, COLUMNAS=4;
  7. typedef int arreglo[FILAS][COLUMNAS];
  8.  
  9. void cargar(arreglo &a, int i, int j);
  10. void mostrar(arreglo a, int i, int j);
  11. int suma(arreglo a, int i, int j);
  12.  
  13. int main()
  14. {
  15. arreglo miarreglo;
  16. srand(time(0));
  17. cargar(miarreglo,0,0);
  18. mostrar(miarreglo,0,0);
  19. cout << "SUMA: " << suma(miarreglo,FILAS-1,COLUMNAS-1) << endl;
  20. system("pause");
  21. }
  22.  
  23. void cargar(arreglo &a, int i, int j)
  24. {
  25.    a[i][j]=1+rand()% 10;
  26.    if(i<FILAS){
  27.     if(j<COLUMNAS){
  28.     cargar(a,i,j+1);
  29. }
  30. else{
  31. cargar(a,i+1,0);
  32. }
  33. }
  34. }
  35.  
  36. void mostrar(arreglo a, int i, int j)
  37. {
  38.    if(i<FILAS){
  39.     if(j<COLUMNAS){
  40.     cout << a[i][j] << " ";
  41.     mostrar(a,i,j+1);
  42. }
  43. else{
  44. cout << endl;
  45. mostrar(a,i+1,0);
  46. }
  47. }
  48. }
  49.  
  50. int suma(arreglo a, int i, int j)
  51. {
  52. if(i==0 && j==0)
  53. return a[i][j];
  54. else
  55. if(i>-1)
  56. if(j>=-1)
  57. return a[i][j]+suma(a,i,j-1);
  58. else
  59. return a[i][j]+suma(a,i-1,j+COLUMNAS-1);
  60. }
;-)
574  Programación / Programación C/C++ / Re: RECURSION en su estado mas puro para invertir un vector! en: 16 Septiembre 2018, 00:56 am
COLUMNAS es solo representativo
Código
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. const int FILAS=3, COLUMNAS=4;
  6. typedef int arreglo[FILAS][COLUMNAS];
  7.  
  8. int suma(arreglo a, int i, int j);
  9.  
  10. int main()
  11. {
  12. arreglo miarreglo={{1,1,1,1},{2,2,2,2},{3,3,3,3}};
  13. cout << "SUMA: " << suma(miarreglo,FILAS-1,COLUMNAS-1) << endl;
  14. system("pause");
  15. }
  16.  
  17. int suma(arreglo a, int i, int j)
  18. {
  19. if(i==0 && j==0)
  20. return a[i][j];
  21. else
  22. if(i>-1)
  23. if(j>=-1)
  24. return a[i][j]+suma(a,i,j-1);
  25. else
  26. return a[i][j]+suma(a,i-1,j+COLUMNAS-1);
  27. }
;-)
575  Programación / Programación C/C++ / Re: Lista simple eliminar nodo segun un valor en: 15 Septiembre 2018, 09:00 am
 ;-)
576  Programación / Programación C/C++ / Lista simple eliminar nodo segun un valor en: 15 Septiembre 2018, 06:13 am
Buenas no entiendo el comportamiento de este procedimiento y mas precisamente en el ciclo for

Código
  1. typedef struct tnodo *pnodo;//Estructura de la lista
  2. typedef struct tnodo{
  3. int dato;
  4. pnodo sig;
  5. };
  6.  
  7. pnodo quitar_nodo(pnodo &lista, int valor)//Metodo quitar nodo
  8. {
  9. pnodo borrado, i;
  10. if(lista==NULL){
  11. borrado=NULL;
  12. }
  13. else{
  14. if(lista->dato==valor){
  15. borrado=lista;
  16. lista=borrado->sig;
  17. borrado->sig=NULL;
  18. }
  19. else{
  20. for(i=lista;i->sig!=NULL && valor!=(i->sig)->dato;i=i->sig);//De aqui en adelante no lo tengo bien en claro, se como lo hace pero el codigo me es incomprensible
  21. if(i->sig!=NULL){
  22. borrado=i->sig;
  23. i->sig=borrado->sig;
  24. borrado->sig=NULL;
  25. }
  26. else{
  27. borrado=NULL;
  28. }
  29. }
  30. }
  31. return borrado;
  32. }
Alguien que me lo explique en cristiano por favor?  ;-)
577  Programación / Programación C/C++ / Re: invertir un vector en C en: 15 Septiembre 2018, 00:40 am
Hola para invertir un vector puedes usar la recursividad
Código
  1. void invertir(arreglo a, int n)
  2. {
  3. if(n>=0)
  4. cout << a[n] << " ";
  5. invertir(a,n-1);
  6. }

O de la forma iterativa

Código
  1. void invertir(arreglo a)
  2. {
  3. for(int i=MAX-1;i>=0;i--)
  4. cout << a[i] << " ";
  5. cout << endl;
  6. }
578  Programación / Programación C/C++ / Re: RECURSION en su estado mas puro para invertir un vector! en: 14 Septiembre 2018, 05:19 am
Código
  1. int suma(arreglo a, int i, int j)
  2. {
  3. if(i==0 && j==0)
  4. return a[i][j];
  5. else
  6. if(i>-1)
  7. if(j>=-1)
  8. return a[i][j]+suma(a,i,j-1);
  9. else
  10. return a[i][j]+suma(a,i-1,j+COLUMNAS-1);
  11. }



Código
  1. void mostrar(arreglo a, int n)
  2. {
  3. if(n>=0)
  4. cout << a[n] << " ";
  5. mostrar(a,n-1);
  6. }


Código
  1. void como_la_realidad(short vida)
  2. {
  3. if(vida<=1){
  4. cout << "Entrando en el sueño";
  5. }
  6. else{
  7. como_la_realidad(vida-1);
  8. cout << " del sueño";
  9. }
  10. }


Mod: No hacer triple post. Usa el botón "Modificar".
579  Programación / Programación C/C++ / Re: Pequeña duda sobre palabra reservada new y espacios en memoria en: 13 Septiembre 2018, 22:42 pm
Si tengo esta estructura cuantos bytes seria por cada nodo?
Código
  1. const int MAX=32;
  2. typedef char tcad[MAX];
  3. typedef struct tfecha{
  4. int dia;
  5. int mes;
  6. int año;
  7. };
  8. typedef struct tdomicilio{
  9. tcad calle;
  10. int numero;
  11. tcad barrio;
  12. };
  13. typedef struct tvehiculo{
  14. tcad marca;
  15. tcad patente;
  16. };
  17. typedef struct thorario{
  18. tcad horaEntrada;
  19. tcad horaSalida;
  20. };
  21. typedef struct tchofer{
  22. int legajo;
  23. tcad nombre;
  24. tcad apellido;
  25. int DNI;
  26. tfecha fecha_nac;
  27. tdomicilio domicilio;
  28. tvehiculo coche;
  29. thorario extras;
  30. int horas_extras;
  31. };
  32. typedef struct tnodo *pnodo;
  33. typedef struct tnodo{
  34. tchofer chofer;
  35. pnodo sig;
  36. };
580  Programación / Programación C/C++ / Una pregunta acerca de mostrar listas circulares en: 13 Septiembre 2018, 06:26 am
Hola a todos, si bien esta es una de las formas mas facil de mostrar por pantalla los datos de una lista circular, pero yo queria saber si esto se puede realizar con un ciclo for porque la verdad no lo se  :huh:
Aqui abajo les dejo el procedimiento de mostrar_lista();
Código
  1. void mostrar(tlista lista)
  2. {
  3. pnodo i=lista.inicio;
  4. if(lista.inicio!=NULL){
  5. do{
  6. cout << "Nodo: " << i->dato << endl;
  7. i=i->sig;
  8. }while(i!=lista.inicio);
  9. }
  10. else{
  11. cout << "LISTA VACIA" << endl;
  12. }
  13. }
Páginas: 1 ... 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 [58] 59 60 61 62 63 64
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines