0no

Ordenar vetor inverso - Recursividade

0no
Oct 18th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.42 KB | None | 0 0
  1. //Função recursiva que ordena os elementos na ordem inversa, não utiliza um vetor adicional.
  2. //Exemplo: vetor[1,2,3,4], resultado vetor[4,3,2,1].
  3.  
  4. class Inicio{
  5.     public static void main(String[] args) {
  6.         int[] a = {5, 5, 8, 8, 6};
  7.         array(a, (a.length - 1));
  8.     }
  9.    
  10.     public static int[] array(int[] b, int num){
  11.         if(num >= 0){
  12.             System.out.println(b[num]);
  13.             return array(b, num - 1);
  14.         }
  15.         return b;
  16.     }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment